Getting started

Is SQL Hard to Learn?

By Owen Middleton · Updated October 2026 · We ran the examples on PostgreSQL 17

No. Your first SQL query is not hard to write. The hard part is to know that your answer is correct.

You need that skill from your first WHERE clause. You can try a first query in the task below.

PostgreSQL can run a query with a logical error and give you a wrong answer with no error message. In a study of 744 students in a university database course, a syntax error was less likely than a logical error to stay in a student's final answer.

We make SQLMaxx Learn, a free SQL course, so we are not neutral on this question.

Is SQL easy to learn at the start?

Yes, at the start, SQL is easy to learn. In SQL, you describe the result that you want. You do not tell PostgreSQL how to find the rows. PostgreSQL selects the way to run your query (PostgreSQL 17 documentation, Planner/Optimizer).

All the examples on this page are on the customers table of a small sample store. There are 70 customers in 22 countries, with one row for each customer. In the country column, each country is a two-letter code, for example GB and DE:

Schema · ecommerce1 table? = nullable
customers
idinteger
nametext
emailtext
city?text
countrytext
created_attimestamptz
is_activeboolean

With this query, you get the customers in London, sorted by name:

SELECT name, country
FROM customers
WHERE city = 'London'
ORDER BY name;
namecountry
Frank Wilson GB
Grace Taylor GB
Uma Allen GB
Victor Young GB
customers in London

Each line of the query is one part of the question:

  • SELECT name, country: the columns that you want.
  • FROM customers: the table.
  • WHERE city = 'London': the rows that you want.
  • ORDER BY name: the order of the rows.

Write your first SQL query

In the editor below, the SELECT line and the FROM line are already there. Add a WHERE line and an ORDER BY line. Then press "Check task 1".

What makes SQL hard to learn?

The hard part is a wrong answer with no error message. PostgreSQL shows an error message for some errors, but not for all errors. In two studies (2019, with Piia Perälä, and 2020), Toni Taipalus sorts errors into four classes, for example syntax errors and logical errors. These two classes are important for a beginner:

  • A syntax error: For most syntax errors, PostgreSQL stops the query and shows an error message. You see the error, and you can try to correct it.
  • A logical error: PostgreSQL runs the query and gives you a result, but the result is not the answer to your question. You get no error message. You can find the error only if you know exactly what data you need.

A SQL error message, then a wrong SQL answer

The question: how many customers are in each country? This query is not correct:

SELECT country, name, COUNT(*) AS customers
FROM customers
GROUP BY country;
PostgreSQL responds column "customers.name" must appear in the GROUP BY clause or be used in an aggregate function

PostgreSQL gives you two ways to correct the query: add name to GROUP BY, or use name in an aggregate function. Add name to GROUP BY, and PostgreSQL runs the query with no error:

SELECT country, name, COUNT(*) AS customers
FROM customers
GROUP BY country, name
ORDER BY country, name;
countrynamecustomers
AT Jade Evans 1
AT Kyle Ford 1
AU Jack Miller 1
AU Karen Anderson 1
AU Yara Scott 1
70 rows, one for each customer · 65 more rows not shown

The customers of the store are in 22 countries, so you must get 22 rows. With name in GROUP BY, you get one row for each customer, and each count is 1. The error message is gone, but the answer is wrong. To get one row for each country, remove name:

SELECT country, COUNT(*) AS customers
FROM customers
GROUP BY country
ORDER BY customers DESC, country;
countrycustomers
US 16
GB 8
CA 4
AU 3
DE 3
customers in each country, correct · 17 more rows not shown

A SQL error with no error message

The question: how many customers do not have London as their city? Count the customers with no city too. There are 70 customers in the store, and 4 of them have London as their city. So the correct count is 66. PostgreSQL runs this query with no error:

SELECT COUNT(*) AS not_in_london
FROM customers
WHERE city <> 'London';
not_in_london
57
wrong: the correct count is 66

9 customers have no city. For these rows, city is NULL. The result of NULL <> 'London' is NULL, not true. PostgreSQL keeps only the rows for which the WHERE condition is true, so PostgreSQL does not count the 9 customers with no city. Add OR city IS NULL to count them:

SELECT COUNT(*) AS not_in_london
FROM customers
WHERE city <> 'London' OR city IS NULL;
not_in_london
66
correct

On your own data, do this check before you use <> on a column: count the rows where the column is NULL. If the count is not 0, decide how to count these rows.

SELECT COUNT(*) AS no_city
FROM customers
WHERE city IS NULL;
no_city
9
customers with no city

Run the query with the error here. Then correct it, and compare the two counts:

SELECT COUNT(*) AS not_in_london
FROM customers
WHERE city <> 'London';

SQL errors in research on students

Taipalus and Perälä (2019) is the study of 744 students at the top of this page. The students could see the correct result table while they wrote each query.

Taipalus (2020) studied the final answers of 987 students in a university database course. The students usually corrected syntax errors, and logical errors were the most common cause of a wrong final answer.

In both studies, the students wrote their queries in SQLite. SQLite accepts a column in the result that is not in GROUP BY and not in an aggregate function (SQLite documentation, Quirks of SQLite). So in SQLite, you get no error message for the first query of the GROUP BY example. In PostgreSQL, you get the error message.

GROUP BY errors were different from other syntax errors. The researchers count a column too many or too few in GROUP BY as a syntax error, but many students did not correct it. Taipalus (2020) links these errors to the cause "ignorance": "insufficient or incorrect knowledge about how SQL or the relational model works", a link that the author says is not certain. The label and the demo above are not the same: the researchers call a wrong GROUP BY column a syntax error, but PostgreSQL gave no error for the extra column name.

Which SQL errors do beginners not correct?

In Taipalus (2020), the errors that students most often did not correct were in conditions, GROUP BY, joins and ORDER BY. The author names five errors as "the most common errors that novices are unable to fix". Here is each error, with an example from the sample store:

  • "Missing expressions": you leave out a condition from the question. For example, you need the active customers in the US, and you write only WHERE country = 'US'.
  • "Extraneous or omitted grouping columns": a column too many or too few in GROUP BY, as in GROUP BY country, name above.
  • "Incorrect comparison operators": the wrong operator or the wrong value in a comparison. For example, you write > in place of >=, or 'Germany' in place of 'DE'.
  • "Missing joins": you do not join a table that you need for the question. For example, you need the orders of each customer, and you use only the customers table.
  • "Missing ordering columns": you leave out a column of the sort order. For example, you need a sort by country and then by name, and you write only ORDER BY country.

A different research group studied more than 160,000 query snapshots from more than 2,300 students (Ahadi and others, 2016). This group uses a different classification. Most of the mistakes that they call "semantic" were of the type "omission". Most of these omissions were in queries for which you need a JOIN, a subquery or GROUP BY.

Joins are in both lists. For three or more tables, read the lesson on how to join multiple tables. With a join, you can also get the same customer in many rows. To show each customer one time, you can use SELECT DISTINCT. See the lesson on DISTINCT, with live examples.

Is SQL easier to learn than Python?

In our view, yes, if your job is to get data from a database. SQL is the language that you use to ask a relational database for data. You saw a complete SQL query above in four short lines. Python is "a high-level general-purpose programming language" for many types of problems (Python documentation). In our view, you learn more before you get your first data from a database with Python.

Which language to learn first is a separate question: SQL or Python first.

Start SQLMaxx Learn lesson 1

SQLMaxx Learn is free structured SQL training in 66 lessons. Lesson 1 is "SELECT and Column Expressions", and you can start it in your browser with no account.

You write each query in a real PostgreSQL database and press "Check answer" to check your result, but you learn only PostgreSQL and see no video.

More questions about how hard SQL is

Can a non-IT person learn SQL?

In our view, yes. For a first query, you need no other programming language: each query on this page is SQL only. The students in the two Taipalus studies studied computer science or information systems, so we cannot apply those results to people from other fields.

Is SQL harder than Excel?

In our view, neither tool is hard for a first task. In SQL, you type a query to get data. We compare the two tools on SQL vs Excel.

Is advanced SQL hard?

Some topics are hard, and not only the advanced ones. Taipalus (2020), with references to earlier studies, calls the self-join "one of the most difficult query concepts" for beginners. One reason that the author gives: in a question for a self-join, you find no hint to join a table to itself. In SQLMaxx Learn, you learn self-joins in lesson 21 (Core SQL tier), window functions first in lesson 38 (Intermediate tier) and recursive CTEs in lesson 52 (Advanced tier).