SQL dialect cheat sheet: MySQL vs PostgreSQL vs SQL Server vs Oracle vs SQLite
By Hammad Rasool · November 28, 2026
Quick answer: most SQL is the same everywhere, but five things change between databases: how names are quoted (`backticks` in MySQL, "double quotes" in PostgreSQL, Oracle and SQLite, [brackets] in SQL Server), how you limit rows (LIMIT vs TOP vs FETCH FIRST), auto-increment columns, upserts, and date functions. The tables below put the same task side by side for MySQL, PostgreSQL, SQL Server, Oracle and SQLite, followed by the results that surprise people when they move a query from one database to another.
How this was checked: on 28 November 2026 every PostgreSQL and SQLite example was run on PostgreSQL 19.0 (through PGlite) and SQLite 3.43.1, and the results shown are what they returned. The MySQL, SQL Server and Oracle columns were checked against each vendor's documentation but not run, so test them on your own server before relying on a version-specific feature.
Quoting, strings and NULL
| Task | MySQL / MariaDB | PostgreSQL | SQL Server | Oracle | SQLite |
|---|---|---|---|---|---|
| Quote a table or column name | `order` | "order" | [order] or "order" | "ORDER" | "order" (also accepts `order` and [order]) |
| Escape a quote in a string | 'O''Brien' or 'O\'Brien' | 'O''Brien' | 'O''Brien' | 'O''Brien' | 'O''Brien' |
| Unquoted names are stored as | As written (table names may be case-sensitive on Linux) | lowercase | As written | UPPERCASE | As written |
| Select without a table | SELECT 1 | SELECT 1 | SELECT 1 | SELECT 1 FROM DUAL (23ai: FROM optional) | SELECT 1 |
| Concatenate strings | CONCAT(a, b) | a || b or CONCAT(a, b) | a + b or CONCAT(a, b) (2025+: a || b) | a || b | a || b |
| Fallback for NULL | IFNULL(x, 0) or COALESCE | COALESCE(x, 0) | ISNULL(x, 0) or COALESCE | NVL(x, 0) or COALESCE | IFNULL(x, 0) or COALESCE |
| String length in characters | CHAR_LENGTH(s) (LENGTH counts bytes) | LENGTH(s) | LEN(s) (ignores trailing spaces) | LENGTH(s) | LENGTH(s) |
| First 4 characters | SUBSTRING(s, 1, 4) | SUBSTRING(s FROM 1 FOR 4) or SUBSTR | SUBSTRING(s, 1, 4) | SUBSTR(s, 1, 4) | SUBSTR(s, 1, 4) |
| Join values from many rows | GROUP_CONCAT(x SEPARATOR ', ') | STRING_AGG(x, ', ') | STRING_AGG(x, ', ') (2017+) | LISTAGG(x, ', ') WITHIN GROUP (ORDER BY x) | GROUP_CONCAT(x, ', ') |
If you only need to quote names safely, use the quote style of your target database everywhere. A reserved word such as order, user or group used as a column name will fail unquoted in every one of these databases. In testing, PostgreSQL rejected `name` with a syntax error, while SQLite accepted all three styles.
Limiting rows, inserting and upserting
| Task | MySQL / MariaDB | PostgreSQL | SQL Server | Oracle | SQLite |
|---|---|---|---|---|---|
| First 10 rows | LIMIT 10 | LIMIT 10 or FETCH FIRST 10 ROWS ONLY | SELECT TOP (10) ... | FETCH FIRST 10 ROWS ONLY (12c+) | LIMIT 10 |
| Rows 21 to 30 (page 3) | LIMIT 10 OFFSET 20 | LIMIT 10 OFFSET 20 | ORDER BY ... OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY | OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY | LIMIT 10 OFFSET 20 |
| Insert many rows at once | VALUES (...), (...) | VALUES (...), (...) | VALUES (...), (...) up to 1,000 rows | INSERT ALL ... SELECT FROM DUAL (23ai: VALUES (...), (...)) | VALUES (...), (...) |
| Get the new row's id | SELECT LAST_INSERT_ID() (MariaDB 10.5+: RETURNING) | INSERT ... RETURNING id | INSERT ... OUTPUT INSERTED.id VALUES ... | RETURNING id INTO :new_id | RETURNING id (3.35+) or last_insert_rowid() |
| Insert or update (upsert) | INSERT ... AS new ON DUPLICATE KEY UPDATE city = new.city | INSERT ... ON CONFLICT (id) DO UPDATE SET city = EXCLUDED.city | MERGE INTO ... WHEN MATCHED THEN UPDATE ... WHEN NOT MATCHED THEN INSERT ... | MERGE INTO ... USING ... ON (...) | INSERT ... ON CONFLICT (id) DO UPDATE SET city = excluded.city (3.24+) |
SQL Server only accepts OFFSET ... FETCH after an ORDER BY, and a single VALUES list there is capped at 1,000 rows. That is why the CSV to SQL converter splits SQL Server output into batches of 1,000 and writes Oracle output as one INSERT per row, which runs on every Oracle version.
Upsert, side by side
An upsert inserts a row, or updates it if a row with the same key already exists. The key column needs a UNIQUE or PRIMARY KEY constraint in every database.
PostgreSQL and SQLite (both tested):
INSERT INTO customers (name, city)
VALUES ('Zoe', 'Quetta')
ON CONFLICT (name) DO UPDATE
SET city = EXCLUDED.city,
visits = customers.visits + 1
RETURNING id, city, visits;
-- PostgreSQL 19: id 3, city Quetta, visits 1
-- SQLite 3.43 (write excluded.city): same resultMySQL 8.0.19 and later (the older VALUES(city) form still works but is deprecated):
INSERT INTO customers (name, city)
VALUES ('Zoe', 'Quetta') AS new
ON DUPLICATE KEY UPDATE city = new.city, visits = visits + 1;SQL Server (Oracle's MERGE has the same shape, with the ON condition in brackets):
MERGE INTO customers AS t
USING (VALUES ('Zoe', 'Quetta')) AS s (name, city)
ON t.name = s.name
WHEN MATCHED THEN
UPDATE SET city = s.city, visits = t.visits + 1
WHEN NOT MATCHED THEN
INSERT (name, city) VALUES (s.name, s.city);Column types
| Task | MySQL / MariaDB | PostgreSQL | SQL Server | Oracle | SQLite |
|---|---|---|---|---|---|
| Auto-increment id | INT AUTO_INCREMENT PRIMARY KEY | INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY (or SERIAL) | INT IDENTITY(1,1) PRIMARY KEY | NUMBER GENERATED ALWAYS AS IDENTITY (12c+) | INTEGER PRIMARY KEY |
| True / false | BOOLEAN (stored as TINYINT(1)), TRUE / FALSE | BOOLEAN, TRUE / FALSE | BIT, 1 / 0 | BOOLEAN in 23ai; before that NUMBER(1), 1 / 0 | INTEGER, 1 / 0 (TRUE and FALSE accepted, stored as 1 and 0) |
| Short text | VARCHAR(255) | VARCHAR(255) or TEXT | NVARCHAR(255) for Unicode | VARCHAR2(255) | TEXT |
| Long text | TEXT / LONGTEXT | TEXT | NVARCHAR(MAX) | CLOB | TEXT |
| Date and time | DATETIME | TIMESTAMP | DATETIME2 | TIMESTAMP (DATE also stores the time) | TEXT in ISO format, e.g. '2026-11-28 09:30:00' |
SQLite does not enforce most column types: a column declared INTEGER will store text if you give it text, unless the table is created as STRICT. In testing, SQLite stored DEFAULT TRUE as the integer 1.
Dates
| Task | MySQL / MariaDB | PostgreSQL | SQL Server | Oracle | SQLite |
|---|---|---|---|---|---|
| Now | NOW() | NOW() | SYSDATETIME() or GETDATE() | SYSTIMESTAMP or SYSDATE | datetime('now') (UTC) |
| Today | CURDATE() | CURRENT_DATE | CAST(GETDATE() AS date) | TRUNC(SYSDATE) | date('now') |
| Add 7 days | d + INTERVAL 7 DAY | d + INTERVAL '7 days' | DATEADD(day, 7, d) | d + 7 | date(d, '+7 days') |
| Days between two dates | DATEDIFF(d2, d1) | d2 - d1 (for DATE values) | DATEDIFF(day, d1, d2) | d2 - d1 | julianday(d2) - julianday(d1) |
PostgreSQL's DATE '2026-11-28' + INTERVAL '7 days' returns a timestamp (2026-12-05 00:00:00), and SQLite's date('2026-11-28', '+7 days') returns the text 2026-12-05. SQLite has no date type, so store dates as ISO text (YYYY-MM-DD) to keep sorting and comparisons correct.
Same query, different result
These are the differences that do not raise an error, so they slip through when a query is copied from one database to another.
| Task | MySQL / MariaDB | PostgreSQL | SQL Server | Oracle | SQLite |
|---|---|---|---|---|---|
| SELECT 7 / 2 | 3.5000 | 3 | 3 | 3.5 | 3 |
| 'Sara' = 'sara' (default setup) | True (case-insensitive collation) | False | True (case-insensitive collation) | False | False (but LIKE is case-insensitive for ASCII) |
| 'a' || 'b' | 0 (|| means OR unless PIPES_AS_CONCAT is set) | 'ab' | Syntax error before SQL Server 2025, 'ab' in 2025 | 'ab' | 'ab' |
| 'Zoe' || NULL | — | NULL | — | 'Zoe' (NULL counts as empty) | NULL |
| CONCAT('Zoe', NULL) | NULL | 'Zoe' | 'Zoe' | 'Zoe' | Not available before 3.44 |
| '' IS NULL | False | False | False | True: an empty string is NULL | False |
- Integer division. PostgreSQL, SQL Server and SQLite drop the fraction when both numbers are integers (tested:
7/2returned 3 in PostgreSQL and SQLite). Write7/2.0or cast one side to a decimal. MySQL's/always returns a decimal; useDIVfor whole numbers. - NULL in a concatenation. In PostgreSQL and SQLite,
name || ' - ' || cityreturned NULL for the row whose city was NULL, while PostgreSQL'sCONCATreturned "Zoe - ". Wrap nullable columns inCOALESCE(city, ''). - Case sensitivity. MySQL and SQL Server compare text case-insensitively with their default collations, so a
WHERE email = ...lookup that works there can miss rows in PostgreSQL or Oracle. PostgreSQL hasILIKE(tested:'Sara' ILIKE 'sara'is true). - Empty strings in Oracle. Oracle stores
''as NULL, soWHERE name = ''never matches. UseWHERE name IS NULL.
Converting data between dialects
When you move data rather than queries, let a tool write the dialect-specific parts. The CSV to SQL, Excel to SQL and JSON to SQL converters have a dialect menu that changes the quoting, column types, booleans and batching to match each column above. Going the other way, SQL to CSV reads INSERT statements from MySQL, PostgreSQL and SQLite dumps. To tidy a query after changing it, use the SQL formatter with its MySQL, T-SQL and PL/SQL modes. For step-by-step walkthroughs, see how to import a CSV into a database and formatting PL/SQL and T-SQL.
FAQ
Is SQL the same in every database?
The core is: SELECT, JOIN, WHERE, GROUP BY, INSERT, UPDATE and DELETE work the same way in all five databases. The differences are in quoting, row limits, auto-increment, upserts, built-in functions and data types, which is what this cheat sheet covers.
What is the SQL Server equivalent of LIMIT?
SELECT TOP (10) ... for the first rows, or ORDER BY ... OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY for paging (SQL Server 2012 and later).
What is the PostgreSQL equivalent of AUTO_INCREMENT?
GENERATED ALWAYS AS IDENTITY (PostgreSQL 10 and later) or the older SERIAL type. Use INSERT ... RETURNING id to get the new value; it replaces MySQL's LAST_INSERT_ID().
Why does my MySQL query with backticks fail in PostgreSQL?
PostgreSQL only accepts double quotes around names. Replace `name` with "name", or leave the quotes off when the name is lowercase and not a reserved word.
Which databases support RETURNING?
PostgreSQL, SQLite 3.35 and later, MariaDB 10.5 and later (for INSERT), and Oracle (with RETURNING ... INTO). MySQL does not; use LAST_INSERT_ID(). SQL Server uses the OUTPUT clause instead.