Most of the SQL you learn works in every database. The differences show up in strings, dates, identifiers and a handful of features one engine has and the other lacks. This reference covers the ones you are most likely to hit when moving a query between PostgreSQL (which LearnWithSQL runs on) and MySQL 8.
Quick reference
| Task | PostgreSQL | MySQL 8 |
|---|---|---|
| Concatenate text | first_name || ' ' || last_name | CONCAT(first_name, ' ', last_name) |
| Quote an identifier | "Order" | `Order` (backticks) |
| Case-insensitive match | ILIKE | LIKE (case-insensitive by default collation) |
| First N rows | LIMIT 10 | LIMIT 10 |
| Truncate to month | DATE_TRUNC('month', d) | DATE_FORMAT(d, '%Y-%m-01') |
| Add an interval | d + INTERVAL '7 days' | DATE_ADD(d, INTERVAL 7 DAY) |
| Current timestamp | now() | NOW() |
| String aggregation | STRING_AGG(name, ', ') | GROUP_CONCAT(name SEPARATOR ', ') |
| Cast | salary::numeric or CAST(...) | CAST(salary AS DECIMAL(10,2)) |
| Full outer join | supported | not supported |
| Conditional count | COUNT(*) FILTER (WHERE ...) | SUM(CASE WHEN ... THEN 1 ELSE 0 END) |
| Upsert | ON CONFLICT (id) DO UPDATE | ON DUPLICATE KEY UPDATE |
| Boolean type | real boolean | TINYINT(1) alias |
Strings and case sensitivity
The biggest surprise for people moving from MySQL is that PostgreSQL text comparison is case-sensitive:
-- PostgreSQL: matches 'King' but not 'king'
SELECT first_name, last_name FROM employees WHERE last_name = 'King';
-- Case-insensitive in PostgreSQL
SELECT first_name, last_name FROM employees WHERE last_name ILIKE 'king';
In MySQL, the default utf8mb4_0900_ai_ci collation is case-insensitive (the ci suffix), so both versions match. If you need the same behaviour everywhere, compare LOWER(column) with a lower-case value.
Also note that || in MySQL means logical OR unless the PIPES_AS_CONCAT mode is enabled, so 'a' || 'b' returns 0 there. Use CONCAT() in portable code.
Dates
PostgreSQL has a rich set of date functions and real interval arithmetic:
SELECT DATE_TRUNC('month', order_date) AS month, COUNT(*) AS orders
FROM orders
WHERE order_date >= CURRENT_DATE - INTERVAL '90 days'
GROUP BY 1
ORDER BY 1;
The MySQL equivalent:
SELECT DATE_FORMAT(order_date, '%Y-%m-01') AS month, COUNT(*) AS orders
FROM orders
WHERE order_date >= CURDATE() - INTERVAL 90 DAY
GROUP BY 1
ORDER BY 1;
EXTRACT(YEAR FROM order_date) works in both and is a good portable choice for pulling out parts of a date.
GROUP BY strictness
PostgreSQL rejects a query that selects a column which is neither grouped nor aggregated. MySQL 8 does too when ONLY_FULL_GROUP_BY is on (the default), but older servers and some hosted setups turn it off, and then MySQL silently returns an arbitrary value for that column. If a query "works in MySQL but fails in PostgreSQL", this is the usual reason, and PostgreSQL is pointing at a real bug.
Features one has and the other lacks
- FULL OUTER JOIN: PostgreSQL only. In MySQL, combine a
LEFT JOINand aRIGHT JOINwithUNION. - FILTER on aggregates: PostgreSQL only. Use
SUM(CASE WHEN …)in MySQL. - DISTINCT ON: PostgreSQL only. Use
ROW_NUMBER()in a subquery for the same "first row per group" result in MySQL. - RETURNING: PostgreSQL can return rows from
INSERT,UPDATEandDELETE; MySQL cannot (MariaDB can for some statements). - Window functions and CTEs: both support them, but MySQL only from version 8.0.
Identifiers and reserved words
PostgreSQL folds unquoted identifiers to lower case, so SELECT FirstName looks for firstname. If a table was created with quoted mixed-case names, you must quote them every time. The simplest habit, used by the LearnWithSQL sandboxes, is lower-case snake_case names that never need quoting.
Which should you learn first?
Learn standard SQL and you know about 90% of both. PostgreSQL is a good first engine because it is strict: it refuses ambiguous GROUP BY queries and comparisons that MySQL would quietly accept, so the habits you form transfer cleanly. The Dialect Switcher on LearnWithSQL shows MySQL, SQL Server, SQLite and Oracle notes next to each lesson for exactly this reason.