Back to articles list Articles Cookbook
8 minutes read

6 Common SQL Syntax Mistakes All Learners Make

Updated on: June 22, 2024

We all make mistakes when learning a new language – especially at the beginning. New words, complicated grammar... Everyone needs time to master a language. But when we get immediate feedback, we can progress more quickly. The same goes for learning SQL. In this article, we'll look at 6 common SQL syntax mistakes most SQL learners make.

Learning SQL can feel like deciphering a complex code, especially when you’re just starting out. I remember the early days of my SQL. I would stare at my screen, puzzled by the errors and wondering what went wrong. It’s a universal experience for every budding SQL developer, and trust me, it gets better with practice.

The beauty of SQL lies in its simplicity and power, but that simplicity can sometimes be deceptive. Tiny errors can lead to big headaches. This guide is here to help you avoid those pitfalls and understand the common mistakes many of us make. Let's dive in!

Mastering SQL Queries

Interactive SQL courses are one way to get immediate feedback on your queries. These courses, like the ones offered on LearnSQL.com, usually introduce new concepts and then ask you to have a go at them right away. If you make a mistake, you'll instantly get a message so you can correct it (and improve your SQL skills). In my opinion, it’s just the best way to learn SQL.

Below is a list of the SQL syntax mistakes that are especially easy for beginners to make. I bet you have made at least one of them a few times in your life! As I explain each SQL syntax mistake, I'll use examples based on the car table exercises from LearnSQL.com's course. If you've done any of these courses, they will be familiar to you; if not, courses are free to try. Start with SQL Basics.

SQL Syntax Mistake #1: Misspelling Table Names

When you start working with databases, you should get to know the table names right away. Let's say we want all the rows and columns from the car table. Will this statement work?

wrong
SELECT * FROM cars;

Oops! It's not working! Fortunately, the error message gives us a hint about the problem. In this case, there is no “cars” table in the database, which means we probably misspelled the table name.

Console: 1. Misspelling Table Names

 

The correct statement is:

correct
SELECT * FROM car;

Now everything should work!

Many common syntax errors in SQL are simply misspellings: for example, typing commodiy instead of commodity or forgetting the underscore in postal_codes. In these cases, the “Table X not found...” message would mean there is a typo in the query and we should correct it.

SQL Syntax Mistake #2: Using Incorrect or Non-Existent Column Names

When you start working with a new database (or with any database that has many columns), always double-check variable names. Unfortunately, SQL is not that smart. If you misspell a word, it will not correct it. Each letter in the word should be correct (and in the correct place).

Let's find the production years for our cars:

wrong
SELECT year FROM car;

Again, something is wrong. Let's see the console.

Console: Using Incorrect or Non-Existent Column Names

 

The “year” column does not exist. So we have to check the table once again (for example, by using SELECT * FROM car to see all the column names) and find the correct name for that column. Instead of year, it is production_year! So we type:

correct
SELECT production_year FROM car;

Now it is working!

The same “Column “x” not found…” message will also occur when you refer to a column from a table you intended (but forgot!) to JOIN.

Suppose there is an additional table called customer that has columns called customer_id, name, and car_id. If we JOIN the car and customer tables, we could match cars and their prices with customer data (using the “car_id” column).

But if we execute the query below…

wrong
SELECT price, name FROM car;

... we'll have a SQL syntax mistake. There is no “name” column in the table car, and unless we tell it otherwise SQL will look for it there. This is why forgetting to join two tables will also generate a “column not found” error. The solution is to do the following:

correct
SELECT price, name FROM car JOIN customer 
ON car.id=customer.car_id;

Need more about SQL JOINs? Here is Your Complete Guide to SQL JOINs (with Resources).

SQL Syntax Mistake #3: Forgetting SELECT List Commas

Now suppose we want to select the brand and model columns from car. We write the following query:

wrong
SELECT brand model FROM car;

Unfortunately, it doesn't work. In SQL, you have to separate column names with commas (as we usually do when making lists in English). All we need to do is add a comma:

correct
SELECT brand, model FROM car;

Mistake fixed! The query will work exactly as we want. Check everything about SELECT in the article SQL Syntax.

SQL Syntax Mistake #4: Leaving Out Quotation Marks

Another thing we need to remember is how to filter text values. In SQL, text values (like a brand of car or a city) are stored in text columns. What if we want to see all Toyotas in our car database? We type:

wrong
SELECT *
FROM car
WHERE brand = Toyota;

We get an error in the console, as shown below:

Console: Leaving Out Quotation Marks

 

It says that there is no Toyota column in the table. When we do not use quotation marks around a text value, SQL treats that value as a column name.

This query will not work because we did not put the value ('Toyota') in single quotation marks. Let's correct the mistake:

correct
SELECT * FROM
car WHERE
brand = 'Toyota';

This is the proper way to filter text values. Note that SQL uses single quotation marks ('text') instead of double ones ("text") as some other programming languages do. Anyone with a programming background should be especially cautious about the kind of quotes they use here!

SQL Syntax Mistake #5: Not Specifying Table Names after SELECTs

Some beginners forget to specify which table they want to select columns from. They write:

wrong
SELECT brand, price;

SQL is just a programming language and it has its rules. If you list columns, you need to specify the table from which the columns should be extracted. This is done with the FROM clause:

correct
SELECT brand, price FROM car;

SQL Syntax Mistake #6: Ordering Statements Incorrectly

Learning SQL grammar is not that complicated. The order in which statements appear is one of its components. Let's try to select cars with a price under $10,000:

wrong
SELECT * WHERE price < 10000 FROM car;

Here we have another instance of common syntax errors in SQL:

Console: Ordering Statements Incorrectly

 

It simply says there is a SQL syntax mistake in the statement. We should look at the statement and see if everything is in the correct order. The order should always be:

  1. SELECT
  2. FROM
  3. WHERE

Now our code should read:

correct
SELECT * FROM car WHERE price < 10000;

All other SQL statements should be written in the correct order. For example:

  • SELECT brand, avg(price)
  • FROM car
  • WHERE price < 100000
  • GROUP BY brand
  • ORDER BY brand

Here are some additional recourses for you:

Keep Learning to Avoid Common Syntax Errors in SQL!

Mistakes are a normal part of learning something new, and SQL is no exception. When you’re just starting out, it’s easy to make the same errors repeatedly. But don’t worry – these beginning mistakes are usually easy to correct. With practice and patience, you’ll quickly overcome them.

Remember, feeling frustrated is part of the process. If you find yourself making common syntax errors over and over, don’t get discouraged. It happens to everyone! Each mistake is a learning opportunity that brings you one step closer to mastering SQL.

One of the best ways to improve is by using an interactive SQL course, like the ones on LearnSQL.com. These courses give you immediate feedback, helping you spot and fix your mistakes right away. As you practice more, you'll find that these errors become less frequent, and your confidence in writing SQL queries will grow. Keep going, you’ve got this!

If you're looking for a great starting point, check out the SQL Basics interactive course on LearnSQL.com. This beginner-friendly course covers the basics of SQL, teaching you how to write and optimize queries. 

You'll learn through practical exercises and real-world examples, making complex concepts easier to understand. The course covers topics like selecting data, filtering results, using JOINs, and more. With clear, step-by-step instructions, you'll build a solid foundation in SQL and gain the confidence to handle various database tasks. 

Plus, you don't need to install anything – everything happens right in your web browser, making it really convenient to start learning right away.

What Would You Add to This List?

What mistakes did you make as a beginning SQLer? What errors do you find yourself making when you're not careful? Share your thoughts and observations in the comments section below. Other SQL students will appreciate it!