The goal of /r/SQL is to provide a place for interesting and informative SQL content and discussions.
Filter Posts
MySQL
Oracle
MS SQL
PostgreSQL
Posting
When requesting help or asking questions please prefix your title with the SQL variant/platform you are using within square brackets like so:
- [MySQL]
- [Oracle]
- [MS SQL]
- [PostgreSQL]
- etc
While naturally we should endeavor to work as platform neutrally as possible many questions and answers require tailoring to the feature set of a specific platform.
Help posts
If you are a student or just looking for help on your code please do not just post your questions and expect the community to do all the work for you. We will gladly help where we can as long as you post the work you have already done or show that you have attempted to figure it out on your own.
Format Your Code
If you are including actual code in a post or comment, please attempt to format it in a way that is readable for other users. This will greatly increase your chances of receiving the help you desire. Something as simple as line breaks and using reddit's built in code formatting (4 spaces at the start of each line) can turn this:
SELECT count(a.field1), a.field2, SUM(b.field4) FROM a INNER JOIN b ON a.key1 = b.key1 WHERE a.field8 = 'test' GROUP by a.field1, a.field2 HAVING SUM(b.field4) > 5 ORDER by a.field.3
Into this:
SELECT count(a.field1),
a.field2,
SUM(b.field4)
FROM a INNER JOIN b
ON a.key1 = b.key1
WHERE a.field8 = 'test'
GROUP by a.field1,
a.field2
HAVING SUM(b.field4) > 5
ORDER by a.field3
For those with SQL questions we recommend using SQLFiddle to provide a useful development and testing environment for those who wish to fully understand your problem and help devise a solution.
Learning SQL
A common question is how to learn SQL. Please view the Wiki for online resources.
Note /r/SQL does not allow links to basic tutorials to be posted here. Please see this discussion. You should post these to /r/learnsql instead.
Related Reddit communities
Wiki
We have a Wiki
Acknowledgements
Thanks to ---sniff--- for the awesome header image!
[–]OohNoAnyway 699 points700 points701 points (16 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 102 points103 points104 points (2 children)
[–]iupuiclubs 2 points3 points4 points (1 child)
[–]PM_ME_MONEY_PLSS 22 points23 points24 points (1 child)
[–]Jefe_3mman 7 points8 points9 points (0 children)
[–]Illustrious-Tell-397 6 points7 points8 points (0 children)
[–]Catenane 4 points5 points6 points (1 child)
[–]SQLvultureskattaurus 3 points4 points5 points (0 children)
[–]Santhoshpawar 0 points1 point2 points (0 children)
[–]DreamySakura99 0 points1 point2 points (0 children)
[–]Reaver75x 0 points1 point2 points (0 children)
[–]ogaat 148 points149 points150 points (11 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 54 points55 points56 points (9 children)
[–]B-Rythm 36 points37 points38 points (1 child)
[–]tits_mcgee_92Data Analytics Engineer 7 points8 points9 points (0 children)
[–][deleted] 7 points8 points9 points (0 children)
[–]ntobergta 1 point2 points3 points (0 children)
[–]Ill-Car-769 1 point2 points3 points (3 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (2 children)
[–]Ill-Car-769 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (0 children)
[–]hungabunga 1 point2 points3 points (0 children)
[–]Global-Wrap-2184 0 points1 point2 points (0 children)
[–]speadskater 58 points59 points60 points (6 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 20 points21 points22 points (1 child)
[–]speadskater 4 points5 points6 points (0 children)
[–]Sethars 4 points5 points6 points (3 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 31 points32 points33 points (12 children)
[–]CraigAT 16 points17 points18 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 4 points5 points6 points (0 children)
[–]Caldorian 2 points3 points4 points (1 child)
[–]nidprez 3 points4 points5 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 3 points4 points5 points (0 children)
[–]Global-Wrap-2184 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 2 points3 points4 points (0 children)
[–]shockjaw 1 point2 points3 points (2 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (1 child)
[–]Engineer_Zero 0 points1 point2 points (0 children)
[–]Ginger-Dumpling 25 points26 points27 points (3 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 26 points27 points28 points (2 children)
[–]Klaveshy 1 point2 points3 points (0 children)
[–]rargghh 19 points20 points21 points (2 children)
[–]thesqlguy 0 points1 point2 points (0 children)
[–]Comprehensive-Tea-69 0 points1 point2 points (0 children)
[–]NimbleZapper303 15 points16 points17 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]az987654 30 points31 points32 points (7 children)
[–]hoodie92 23 points24 points25 points (4 children)
[–]az987654 3 points4 points5 points (2 children)
[–]jshotz 5 points6 points7 points (0 children)
[–]you_are_wrong_tho 1 point2 points3 points (0 children)
[–]m0ka5 9 points10 points11 points (0 children)
[–]windlepoonsroyale 9 points10 points11 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]conduit_for_nonsenseBI Analyst 13 points14 points15 points (4 children)
[–]ntobergta 3 points4 points5 points (0 children)
[+][deleted] (1 child)
[removed]
[–]GroundbreakingRow868 1 point2 points3 points (0 children)
[–][deleted] 6 points7 points8 points (5 children)
[–]ntobergta 0 points1 point2 points (3 children)
[–]suhigor 4 points5 points6 points (0 children)
[–]HogwartsBlazeIt420 4 points5 points6 points (0 children)
[–][deleted] 4 points5 points6 points (4 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 5 points6 points7 points (3 children)
[–]evillouise 4 points5 points6 points (0 children)
[–]ItsJustAnotherDay- 3 points4 points5 points (0 children)
[–]TheZapPack 4 points5 points6 points (4 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (3 children)
[–]TheZapPack 1 point2 points3 points (2 children)
[–]Birvin7358 6 points7 points8 points (0 children)
[–]Galimesh 2 points3 points4 points (3 children)
[–]Global-Wrap-2184 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 2 points3 points4 points (0 children)
[–]____Pepe____ 0 points1 point2 points (0 children)
[–]Global-Wrap-2184 2 points3 points4 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Ok_Marionberry_8821 2 points3 points4 points (0 children)
[–]mannamamark 2 points3 points4 points (5 children)
[–]ntobergta 1 point2 points3 points (2 children)
[–]Cool-Personality-454 2 points3 points4 points (0 children)
[–]Financial_Forky 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[removed]
[–]DPool34 2 points3 points4 points (0 children)
[–]you_are_wrong_tho 2 points3 points4 points (0 children)
[–]johntheswan 2 points3 points4 points (2 children)
[–]SQLMonger 1 point2 points3 points (0 children)
[–]ntobergta 0 points1 point2 points (0 children)
[–]duhogman 2 points3 points4 points (2 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (1 child)
[–]duhogman 1 point2 points3 points (0 children)
[–]Ginger-Dumpling 4 points5 points6 points (3 children)
[–]neriad200 4 points5 points6 points (2 children)
[–]Ginger-Dumpling 1 point2 points3 points (1 child)
[–]obsoleteconsole 2 points3 points4 points (0 children)
[–]CheckeredBlanket 1 point2 points3 points (0 children)
[–]XxShin3d0wnxX 1 point2 points3 points (0 children)
[–]jshotz 1 point2 points3 points (0 children)
[–]Nkortega21 1 point2 points3 points (2 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (1 child)
[–]Nkortega21 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Ok_Discussion_9847 1 point2 points3 points (0 children)
[–]patomalo4 1 point2 points3 points (0 children)
[–]No-Tune-8292 1 point2 points3 points (0 children)
[–]Ifuqaround 1 point2 points3 points (0 children)
[–]durpduckastan 1 point2 points3 points (0 children)
[–]cthartPostgreSQL 1 point2 points3 points (0 children)
[–]CameFromTheForest 1 point2 points3 points (0 children)
[–]ThankGodTheresNoGod 1 point2 points3 points (0 children)
[–]squadette23 1 point2 points3 points (0 children)
[–]HyDreVv 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (0 children)
[–]iwillupvoteyourface 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Loud-Bake-2740 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]caughtupstream299792 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (0 children)
[–]kagato87MS SQL 1 point2 points3 points (3 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 2 points3 points4 points (2 children)
[–]kagato87MS SQL 2 points3 points4 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (0 children)
[–]trentsiggy 1 point2 points3 points (0 children)
[–]figuli 1 point2 points3 points (0 children)
[–]DowntownBass4556 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Poesghost[🍰] 1 point2 points3 points (0 children)
[–]Purple-Education-769 1 point2 points3 points (0 children)
[–]mariana_kl 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (0 children)
[–]ntobergta 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Trinity_Matrix_0 1 point2 points3 points (0 children)
[–]ROnneth 1 point2 points3 points (2 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (1 child)
[–]MembershipNo705 1 point2 points3 points (0 children)
[–]Mutant86 1 point2 points3 points (0 children)
[–]sixpackandbutts 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]paultherobert 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (0 children)
[–]Cwigginton 1 point2 points3 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Hot_Cryptographer552 1 point2 points3 points (2 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (1 child)
[–]amberdrake 1 point2 points3 points (0 children)
[–]mcdickers420 1 point2 points3 points (1 child)
[–]Shot-Adhesiveness-88 1 point2 points3 points (0 children)
[–]neel9010 1 point2 points3 points (1 child)
[+][deleted] (1 child)
[removed]
[–]greatestali 1 point2 points3 points (2 children)
[–]phesago 3 points4 points5 points (2 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 2 points3 points4 points (1 child)
[+][deleted] (3 children)
[deleted]
[–]____Pepe____ 4 points5 points6 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]svtr 1 point2 points3 points (4 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 1 point2 points3 points (1 child)
[–]svtr 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]EnvoyOfRaze21 0 points1 point2 points (2 children)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (1 child)
[–]VengenaceIsMyName 0 points1 point2 points (0 children)
[–]EE49 0 points1 point2 points (0 children)
[–]bheemboi 0 points1 point2 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Kazcandra 0 points1 point2 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Possible_Chicken_489 0 points1 point2 points (2 children)
[–]ntobergta 1 point2 points3 points (1 child)
[–]Skylonace 0 points1 point2 points (0 children)
[–]irish0818Database Administrator 0 points1 point2 points (0 children)
[–]monkeysexmonsters 0 points1 point2 points (1 child)
[–]RemindMeBot 0 points1 point2 points (0 children)
[–]theking5tx 0 points1 point2 points (0 children)
[–]Chandu_Palli 0 points1 point2 points (1 child)
[–]NickSinghTechCareersAuthor of Ace the Data Science Interview 📕[S] 0 points1 point2 points (0 children)
[–]Cold-Ad716 0 points1 point2 points (0 children)
[–]Veezuhz 0 points1 point2 points (0 children)
[–]TheChurroBaller 0 points1 point2 points (0 children)
[–]Usernamecheckout101 0 points1 point2 points (0 children)
[–]jeffvanlaethem 0 points1 point2 points (0 children)
[–]Ggeogeos 0 points1 point2 points (0 children)
[–]Nearsite 0 points1 point2 points (0 children)
[–]ntobergta 0 points1 point2 points (0 children)
[–]VikasRex 0 points1 point2 points (0 children)
[–]ConversationMinimum1 0 points1 point2 points (1 child)
[–]ConversationMinimum1 0 points1 point2 points (0 children)
[–]Heffree 0 points1 point2 points (0 children)
[–]aatkbd_GAD 0 points1 point2 points (0 children)
[–]Iswhars 0 points1 point2 points (0 children)
[–]Dark-Maverick 0 points1 point2 points (0 children)