Back to SQLGenie

Common SQL Errors, Fixed in Plain English

Eight SQL errors people run into every day — what they actually mean, why they happen, and the corrected query you can copy. Stuck on a different one? Fix My SQL repairs it for free, no account needed.

MySQL

MySQL Error 1064: “You have an error in your SQL syntax”

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order WHERE status = 'active''

Why it happens

Error 1064 is MySQL's generic syntax error — the part it quotes is where it gave up, so look just before that token. The most common cause is using a reserved word (like order, group, or key) as a table or column name without backticks. Other frequent causes are a missing comma between columns and mismatched quotes around strings.

Broken

SELECT id, total
FROM order
WHERE status = 'active';

Fixed

SELECT id, total
FROM `order`
WHERE status = 'active';

Backticks tell MySQL that order is a table name, not the ORDER keyword. The better long-term fix is renaming the table to something like orders so you never need the backticks.

Fix this in SQLGenie — free
PostgreSQL

PostgreSQL: “syntax error at or near …”

ERROR:  syntax error at or near ","
LINE 1: SELECT name, email FROM customers, WHERE active = true;

Why it happens

PostgreSQL names the exact token where parsing failed — the mistake is almost always right before it. Here a stray comma after the table name makes Postgres expect another table and find WHERE instead. The same error appears for misspelled keywords, a missing FROM, or a missing closing parenthesis.

Broken

SELECT name, email
FROM customers,
WHERE active = true;

Fixed

SELECT name, email
FROM customers
WHERE active = true;

Remove the stray comma. When you see this error, read the query backwards from the quoted token — the typo is usually one word earlier.

Fix this in SQLGenie — free
SQL Server

SQL Server: “Incorrect syntax near 'LIMIT'”

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'LIMIT'.

Why it happens

LIMIT is MySQL and PostgreSQL syntax — SQL Server doesn't understand it. This error almost always means the query was written for a different database and run against SQL Server. The SQL Server equivalent is TOP, placed right after SELECT, or OFFSET/FETCH for paging.

Broken

SELECT *
FROM products
ORDER BY price DESC
LIMIT 10;

Fixed

SELECT TOP 10 *
FROM products
ORDER BY price DESC;

Replace LIMIT 10 with TOP 10 directly after SELECT. For paged results use ORDER BY ... OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY.

Fix this in SQLGenie — free
MySQL

MySQL Error 1054: “Unknown column … in 'field list'”

ERROR 1054 (42S22): Unknown column 'custmer_id' in 'field list'

Why it happens

The column name in your query doesn't exist in the table. Most of the time it's a simple typo — custmer_id instead of customer_id. A sneakier cause is wrapping a string in double quotes while the ANSI_QUOTES setting is on, which makes MySQL treat "John" as a column name instead of a value.

Broken

SELECT custmer_id, total
FROM orders;

Fixed

SELECT customer_id, total
FROM orders;

Check the spelling against your actual table definition (SHOW COLUMNS FROM orders). And always use single quotes for text values — double quotes are for names.

Fix this in SQLGenie — free
PostgreSQL

PostgreSQL: “column … does not exist”

ERROR:  column "John" does not exist
LINE 1: SELECT * FROM users WHERE name = "John";

Why it happens

In PostgreSQL, double quotes mean “this is a table or column name”, not a string. So WHERE name = "John" asks Postgres to compare two columns — and there is no column called John. Text values always need single quotes.

Broken

SELECT *
FROM users
WHERE name = "John";

Fixed

SELECT *
FROM users
WHERE name = 'John';

Swap the double quotes for single quotes. Double quotes are only for names that contain capitals or spaces, like "orderDate".

Fix this in SQLGenie — free
MySQL

“Column 'id' in field list is ambiguous”

ERROR 1052 (23000): Column 'id' in field list is ambiguous
-- PostgreSQL: ERROR:  column reference "id" is ambiguous
-- SQL Server: Msg 209 — Ambiguous column name 'id'.

Why it happens

Two joined tables both have a column with that name, so the database cannot tell which one you mean. It happens most often with id, name, created_at and status once a JOIN is added to a query that used to work on a single table.

Broken

SELECT id, name, total
FROM customers
JOIN orders ON orders.customer_id = customers.id;

Fixed

SELECT c.id AS customer_id,
       c.name,
       o.total
FROM customers c
JOIN orders o ON o.customer_id = c.id;

Give every table a short alias and prefix each column with it. Adding AS aliases to same-named columns also stops your application code from silently overwriting one with the other.

Fix this in SQLGenie — free
MySQL

MySQL Error 1062: “Duplicate entry … for key”

ERROR 1062 (23000): Duplicate entry 'ada@example.com' for key 'users.email_unique'
-- PostgreSQL: ERROR:  duplicate key value violates unique constraint "users_email_key"

Why it happens

A UNIQUE index or PRIMARY KEY already holds that value, and your INSERT or UPDATE would create a second copy. The key name in the message tells you which constraint and therefore which column(s) clashed. Common causes: re-running an import, a retried request, or an auto-increment counter that fell behind after rows were inserted with explicit IDs.

Broken

INSERT INTO users (email, name)
VALUES ('ada@example.com', 'Ada');

Fixed

-- MySQL: keep the existing row, update it instead
INSERT INTO users (email, name)
VALUES ('ada@example.com', 'Ada')
ON DUPLICATE KEY UPDATE name = VALUES(name);

-- PostgreSQL equivalent
INSERT INTO users (email, name)
VALUES ('ada@example.com', 'Ada')
ON CONFLICT (email) DO UPDATE SET name = EXCLUDED.name;

Decide what should happen on a clash: update the existing row (upsert), skip it (INSERT IGNORE / ON CONFLICT DO NOTHING), or fix the duplicate data. Never drop the unique constraint to make the error go away — it is the only thing keeping duplicates out.

Fix this in SQLGenie — free
PostgreSQL

“column … must appear in the GROUP BY clause”

ERROR:  column "orders.order_date" must appear in the GROUP BY clause or be used in an aggregate function
-- MySQL (ONLY_FULL_GROUP_BY): Expression #2 of SELECT list is not in GROUP BY clause…

Why it happens

Once rows are grouped, each group is a single output row — so every selected column must either be one of the grouping columns or be wrapped in an aggregate like SUM, COUNT or MAX. Otherwise the database would have to pick one value out of many at random. MySQL allowed this in older versions, which is why queries break after ONLY_FULL_GROUP_BY is switched on.

Broken

SELECT customer_id, order_date, SUM(total)
FROM orders
GROUP BY customer_id;

Fixed

SELECT customer_id,
       MAX(order_date) AS last_order,
       SUM(total) AS total_spent
FROM orders
GROUP BY customer_id;

Either aggregate the extra column (MAX for the latest date) or add it to GROUP BY — but adding it changes the meaning, giving you one row per customer per date instead of one per customer.

Fix this in SQLGenie — free

A different error message?

Paste your broken query into SQLGenie's Fix My SQL mode — it repairs the syntax, checks it against your tables, and explains what went wrong. Free, no account, nothing stored.

Open Fix My SQL