HACKER Q&A
📣 s-stude

Junior SQL developers – How do you learn SQL?


I have a question to junior software developers.....

I've been an engineer for last 12 years and during my career I've been mentoring people and helping them learn SQL. I used different approaches but did not find any better approach from learning by [doing] writing SQL queries and solving tasks. Even if it was by leveraging the AdventureWorks database, and/or a real world production database.

So my question to people who just entering into any developer role and/or learning just SQL....

How do you learn SQL now, and what is the best approach for you personally?


  👤 testaaajxjd Accepted Answer ✓
I maintain the most popular SQLite3 library for a common programming language (2 million downloads per month).

The only reason I learned SQL is to perform SQL injections and hack shit..

Now I get to fix bugs in SQLite3 on a monthly basis.. I guess karma exists after all lol.


👤 thedookmaster
https://sqlbolt.com/ and then https://sqlzoo.net/ were great places for me to start.

👤 KiranRao0
https://pgexercises.com/

Blurb from their homepage:

Welcome to PostgreSQL Exercises! This site was born when I noticed that there's a load of material out there to help people learn about SQL, but not a great deal to make it easy to learn by doing. PGExercises provides a series of questions and explanations built on a single, simple dataset


👤 ducharmdev
I didn't really learn SQL until being given small tasks at work that involved some basic scripting. Requests for populating tables with new data so admins wouldn't have to manually input it from the web UI was a common one. That in particular was helpful because:

1. Performance is not usually as important for one-time scripts like these.

2. It gets you familiar with your database and the relationships between entities in your product.

3. It shows you how powerful SQL is. With a few hours writing a single script, I saved users many more hours that would've been spent entering it all manually.

The other benefit of this approach, it's easier for senior developers to review too. You can give feedback like, "this works fine for this use-case, but here's something you can do in situations where performance is a concern" and provide some useful tips in PR comments.


👤 fifilura
Not so much about how I learned but how I teach.

Whenever I want to explain how one can do things in SQL I pull up a google/excel sheet and write down some sample data that resembles the problem.

When multiple tables are involved I just write the samples in two different locations within the same sheet.

After that I can just jot down the resulting table below (without writing the actual sheet commands) and maybe some instruction.

Makes all concepts very clear, for example when explaining n:m joins or window functions. Or just the general "table programming" concepts where you add columns rather than variables when you want something done.

Particularly well suited now in covid times when I have to explain things remotely.

SQL and sheets programming are just very closely related.


👤 Jcowell
I had a bit of experience my freshmen year of college by working on a personal project that I abandoned.

When I got hired as a SQL Developer with little experience. I got a rundown on my employers database and tables and then tried my best. Google and Stack was the best teacher and with each work assignment I learned something new or a better way to do what I did before. Often the SQL queries I wrote would require updates and I would put in better solutions.

There’s still a ton of stuff I don’t know and I made a lot of mistakes along the way , but I still feel like this was the best learning experience for me.


👤 searchableguy
CMU database youtube channel: https://youtube.com/c/CMUDatabaseGroup

Postgres documentation: https://www.postgresql.org/docs/

Being forced to solve a challenging problem keeps me going regardless of what it is. I am not a huge fan of exercises without an end result.


👤 adrianmonk
This is about how I learned it many years back, but it worked well for me.

(1) I was starting with Oracle, so I read through Oracle's Database Concepts (https://docs.oracle.com/cd/B19306_01/server.102/b14220/toc.h...). This contains unnecessarily deep technical detail (which I skimmed), but I learn more easily if I have a strong footing in the concepts so I don't feel disoriented. For example, it was helpful to understand transactions (section 4), undo (section 3), and the data dictionary (section 7; later made it easier to understanding the DDL / DML distinction), consistency (section 13). It also contains an overview of some important SQL concepts in section 24 such as cursors and the fact that there's an optimizer which figures out how to run your query.

(2) I read about database normalization. Understanding how to put things in first, second, and third normal forms was extremely helpful in reshaping how I think of data structures. Learning to use a database is not just about how to write a query. It's also about how to model data. (What does relational, as in relational database, mean anyway?) Even if you're not creating tables, understanding how they are probably organized helps you query them. And once you understand basic modeling stuff like normalization, you can move on to advanced stuff like denormalization. Another part of modeling is keys (natural vs. surrogate/synthetic keys, composite keys, foreign keys, etc.).

(3) I practiced writing SQL queries and learned all the joins, aggregate functions, analytic functions, etc.


👤 coopreme
T-sql with pencil and paper. Visualize the problem with tables and relationships (boxes and lines with crows feet). Going through normal forms may be valuable but I like to tell them to just jump to entities and relationships. Once they can draw a “map” of their dB, and it’s usually much simpler than they first expected, then code it out on the nearest computer box.

👤 sedeki
There is a book on ANSI SQL that I've used: https://www.amazon.com/SQL-Complete-Reference-James-Groff/dp...

👤 ipaddr
Make them read ask tom questions and answers. It really helped me understand real world cases.

https://asktom.oracle.com/pls/apex/f?p=100:1000::::::


👤 markus_zhang
I just learned the basics in sqlzoo and the rest on job, should be quick. The problem with learning is that students have no idea about real world requirements so they can only go for very generetic ones (average revenue last week). The key, IMO, is to connect with real world business requirements and start writing queries.

I worked as a BA and now work in BI so it's common for me to write long and complex queries. Most of them due to bad table structure but we can't do much so have to go around.


👤 joshxyz
Reading official docs (be it postgresql, clickhouse, elasticsearch, redis), a lot of googling and stackoverflow, reading blogs and watching presentations on latest developments (like Altinity does for ClickHouse).

Thing is I want to cover the latest stable version of tools im using so i can take advantage of their latest features that might be absent on older ones and not covered by older third party content. The latest stable docs and changelogs are my best source for that.


👤 s-stude
Thanks to everyone for all comments here.

I made https://interactivesql.com to help all those people who just start to learn databases, SQL, queries, and more.

I am compiling 120+ lessons now to cover everything from the basics (select, join, group by, to CTEs, Analytic Functions, performance, reporting, and more)

Hope this helps. Feel free to let me know what do you think about it.


👤 runawaybottle
In college my prof had this book she made with maybe a thousand sql drills with answers. I never went to the class and just drilled all the problems and somehow got good at sql around that time.

Need to find that book again, but I think sql is something you need to drill.

I’ll take a look at some of the links in this thread, and I’m hoping one of them is just a giant bank of sql drills, and would be great if anyone knows of similar books/sites.


👤 spacemanmatt
I leveled up by helping people on #postgresql (freenode) if I wasn't getting help, myself. I still think highly of the practice.

👤 castlecrasher2
I'm not a junior, but my best learning came from real examples in my first role. Then when I had some experience, researching advanced functions such as window functions and CTEs, AKA the result of answering "why does this query take ten minutes to run and how do I optimize it?"

👤 giantg2
Learning by doing is the best. It doesn't matter if some other resource is used, if I'm not getting at least one piece of work per month requiring me to meaningfully use it, then I'm not going to get/stay good at it.

👤 mikewarot
I learned by doing queries in Microsoft Access 2000, then looking at the query in "SQL View". The nice thing about Access is that it managed table relations for you, so master/detail tables are almost trivial.

👤 mraza007
So I have been learning sql since the past month and I have been using the course on udemy called SQL bootcamp by Colt Steele it’s pretty good and the instructor explains stuff in an easy and detailed manner

👤 taf2
I found hacking on Wordpress was a great way to learn about joins