|SQL Snippets - Crowdsourcing SQL Queries|
|Written by Nikos Vaggalis|
|Friday, 20 August 2021|
A curated collection of helpful and reusable SQL snippets sounds like a really good resource to know about and to contribute to.
In SQLBolt - Learn SQL The Interactive Way I highlighted an interactive resource for learning the basics of SQL. Now I've found a way for you to store and share your own snippets of SQL code and find useful code to use without re-inventing it.
As you work with SQL day by day you'll accumulate a hefty amount of SQL code. when just maybe you've written a state of the art query that you are eager to share with your colleagues or the rest of the world.That raises two questions:where do you store that snippet for clean and easy retrieval and afterwards how do you share it with the world?
So do you store it in numerous plain .txt files or in your favorite notepad application like Joplin or Notion? Then do you share it by emailing it,uploading it on paste bin and the like or submit it to your GitHub repository?
All these solutions do not scale;for example if you go the GitHub way and someone wants to upgrade your snippet he has to go through forking your repo and then having to submit a pull request for you to amend, while when going Pastebin you can't have things like a discussion, upvoting or favoring the snippet.
The solution to all that is SQL Snippets,a crowdsourced community resource that uses Discourse as the place to share,collaborate and socialize on your snippets.Of course there's also the educational aspect of the matter, where you actually learn by going through those user posted and commented sql queries.
So inside SQL Snippet's premises you can:
You can find the snippets categorized by the following DBMSs:
and further distil you search by sorting posts by popularity or tags:
For example under the PostgreSql category and "date-time" tag we find a snippet named "Filter for last X days", useful in cases you only want to return the last X days of a query (e.g. last 30 days) and you want that to always be up to date (dynamic):
Other snippets you can find are on:
As a matter of fact I jumped right in making my very first contribution, Removing duplicate rows, inspired from my oldie SQL Workshop - Removing Duplicate Rows.
As seen in the example above, snippets can also have nested embedded snippets like GitHub gists, but based on the Count platform, a live SQL notebook something which allows running your query on live data and checking the results in real time.
Embeddable snippets are currently in beta and not available to non-privileged users, who for now will have to just use the markdown editor of Discourse to document their snippet. But word is that after this feature comes out of testing it is going to be provided free of charge to all.
So take your code out of your treasure box and put it online.This way you can archive, collaborate, and help others all at the same time.
SQLBolt - Learn SQL The Interactive Way
SQL Workshop - Removing Duplicate Rows
SQL Workshop - Selecting columns without including a non-aggregate column in the group by clause
SQL Workshop - Subselects And Join
To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
or email your comment to: email@example.com
|Last Updated ( Friday, 20 August 2021 )|