How to learn SQL

Learning SQL means learning to ask a database questions: SELECT the columns you want FROM a table, filter rows with WHERE, sort with ORDER BY, then join and group tables. You need a free database and a sample table, then four skills:

Dark gray servers stacked in a rack with green indicator lights
A server rack, the kind of machine a PostgreSQL database runs on.Photo: heladodementa / Pixabay
  1. 1

    SELECT and FROM

    Which columns, from which table.

  2. 2

    WHERE

    Which rows to keep.

  3. 3

    ORDER BY

    How to sort the result.

  4. 4

    JOIN and GROUP BY

    Combine and summarize tables.

Learn in Evernote. Clip the docs, let the AI Assistant fix your code, and search any snippet.

Start your coding notebook in Evernote

How to learn SQL in 6 steps

  1. 1

    Install a free database

    PostgreSQL and SQLite are free. The PostgreSQL documentation includes a tutorial that builds a sample weather table.

  2. 2

    Learn SELECT

    A SELECT statement has a select list (the columns), a table list (FROM) and optional conditions. SELECT * returns all columns.

  3. 3

    Filter with WHERE

    Keep only the rows you need: WHERE city = 'San Francisco' or WHERE total > 100.

  4. 4

    Sort with ORDER BY

    ORDER BY total DESC lists the biggest first. Without BY, PostgreSQL reports a syntax error.

  5. 5

    Join and group

    Combine tables with JOIN, and summarize with GROUP BY and functions like COUNT and SUM.

  6. 6

    Practice on your own data

    Load a spreadsheet you care about into a table and answer real questions with it.

A 4-week SQL plan

Following the PostgreSQL tutorial, about 30 minutes a day
  1. 2Week 1Install PostgreSQL. Create the weather table and SELECT from it.
  2. 3Week 2WHERE with numbers, text and dates.
  3. 4Week 3ORDER BY and LIMIT. Answer: the 5 coldest days.
  4. 5Week 4Join weather to a cities table; COUNT rows by city with GROUP BY.

Free coding practice log

One entry per session. Copy it, or save it to your Evernote account and keep your snippets in the same note.

Date: [day] · Time spent: [minutes]

Topic: [one concept, like for loops or functions]

Source: [tutorial, chapter or video, with its link]

What I built: [a small program, in one line]

Error I hit: [the last line of the error message]

How I fixed it: [one sentence, plus the corrected snippet]

Next session: [the next concept to learn]

Trusted by Millions Worldwide

4.4

2,100+ reviews on G2

4.4

8,200+ reviews on Capterra

4.4

73,000+ reviews on App Store

248M

Registered users

SQL learning questions

Can I learn SQL for free?

Yes. PostgreSQL and SQLite are free, and the PostgreSQL documentation has a built-in tutorial.

What is SQL used for?

Retrieving, adding, changing and summarizing data stored in relational databases.

What should I learn first in SQL?

SELECT and FROM, then WHERE and ORDER BY. After that, JOIN and GROUP BY.

What does SELECT * mean?

It returns all the columns of the table. The PostgreSQL tutorial calls * a shorthand for all columns.

How long does it take to learn SQL?

The PostgreSQL tutorial covers SELECT, WHERE, ORDER BY, joins and aggregate functions in chapters 2.5 to 2.7. How long it takes depends on your schedule.

Do I need to learn programming before SQL?

No. SQL is its own language. The PostgreSQL tutorial starts with SELECT and needs no other programming language.

How to learn SQL with Evernote

Keep one notebook for SQL: the tutorial pages you clip, your queries, and every error you fixed.

  1. 1

    Clip the querying lesson.

    Save the PostgreSQL querying lesson with the Web Clipper. Keep it in a notebook called Learning SQL, with the weather table example and its link.

  2. 2

    Ask why the query fails.

    Put the orders query and its syntax error in a note. Ask the AI Assistant why sorting needs ORDER BY, and accept the corrected line.

  3. 3

    Find ORDER BY again.

    Search for "ORDER BY" when you need the syntax again. Evernote finds it in your PostgreSQL clip and in the practice note, code blocks included.

  • You can also ask the Assistant for a practice task that repeats every day.
  • You can also ask the AI Assistant to quiz you on a chapter you clipped, one question at a time.

Every snippet, error and fix in one place

Clip the docs you learn from, ask the AI Assistant why your code breaks, and find any snippet again by searching for it.

Start for free