Learn SQL: where to start?

Learn SQL: where to start?

Updated on

Want to learn SQL but not sure where to start? This guide gives you a clear order for the 16 topics you need, from your first SELECT query to window functions, each with a reference card and exercises with solutions. Nothing to install: you practice everything in your browser.

What is SQL?

SQL (Structured Query Language) is the language used to query relational databases: data stored in tables, with rows and columns, like a spreadsheet but much bigger. You use it to read, filter, group and combine that data. PostgreSQL, MySQL, SQLite, SQL Server and Oracle all speak SQL, with small syntax differences.

It is a skill in demand far beyond developers: data analysts, product managers, marketing, finance… As soon as you work with data, being able to write a query saves hours.

How long does it take to learn SQL?

The basics (reading, filtering, sorting, grouping, joining two tables) take a few weeks with a little practice every day: twenty regular minutes beat three hours once a month. Advanced topics, like CTEs and window functions, then take a few more weeks. What matters most is not reading, but writing queries.

Step 1: read data

Start by learning to pick columns, filter rows and sort the result. It is the basis of every other query.

Step 2: summarise data

Next, learn to compute totals, averages and counts, overall and then per group.

Step 3: combine several tables

This is the step that really makes the difference: useful data is almost always spread across several tables.

Step 4: go further

These topics set experienced profiles apart and often come up in interviews.

Practice a little every day

Reading a course is not enough: you remember by writing queries, getting them wrong, then fixing them. Three ways to practice with SpeedQL:

The most common beginner mistakes

  • Writing column = NULL instead of column IS NULL: a comparison with NULL is never true.
  • Showing a column in SELECT without putting it in GROUP BY or in an aggregate.
  • Putting a condition on COUNT or SUM in WHERE instead of HAVING.
  • Forgetting the ON condition of a join, which combines every row with every other row.
  • Using NOT IN with a subquery that can return NULL: prefer NOT EXISTS.

What next?

Once you have practiced the 16 topics, install a real database (SQLite or PostgreSQL, both free) and query a dataset you care about: sport, films, your own spending… If you are preparing for an interview, review the SQL interview questions with answers, and keep the SQL cheat sheet at hand, with its table of differences between SQLite, PostgreSQL and MySQL.

Start now

Your first query is waiting: free, no sign-up, right in your browser.

Start with SELECT