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

TaskMySQL / MariaDBPostgreSQLSQL ServerOracleSQLite
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 asAs written (table names may be case-sensitive on Linux)lowercaseAs writtenUPPERCASEAs written
Select without a tableSELECT 1SELECT 1SELECT 1SELECT 1 FROM DUAL (23ai: FROM optional)SELECT 1
Concatenate stringsCONCAT(a, b)a || b or CONCAT(a, b)a + b or CONCAT(a, b) (2025+: a || b)a || ba || b
Fallback for NULLIFNULL(x, 0) or COALESCECOALESCE(x, 0)ISNULL(x, 0) or COALESCENVL(x, 0) or COALESCEIFNULL(x, 0) or COALESCE
String length in charactersCHAR_LENGTH(s) (LENGTH counts bytes)LENGTH(s)LEN(s) (ignores trailing spaces)LENGTH(s)LENGTH(s)
First 4 charactersSUBSTRING(s, 1, 4)SUBSTRING(s FROM 1 FOR 4) or SUBSTRSUBSTRING(s, 1, 4)SUBSTR(s, 1, 4)SUBSTR(s, 1, 4)
Join values from many rowsGROUP_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

TaskMySQL / MariaDBPostgreSQLSQL ServerOracleSQLite
First 10 rowsLIMIT 10LIMIT 10 or FETCH FIRST 10 ROWS ONLYSELECT TOP (10) ...FETCH FIRST 10 ROWS ONLY (12c+)LIMIT 10
Rows 21 to 30 (page 3)LIMIT 10 OFFSET 20LIMIT 10 OFFSET 20ORDER BY ... OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLYOFFSET 20 ROWS FETCH NEXT 10 ROWS ONLYLIMIT 10 OFFSET 20
Insert many rows at onceVALUES (...), (...)VALUES (...), (...)VALUES (...), (...) up to 1,000 rowsINSERT ALL ... SELECT FROM DUAL (23ai: VALUES (...), (...))VALUES (...), (...)
Get the new row's idSELECT LAST_INSERT_ID() (MariaDB 10.5+: RETURNING)INSERT ... RETURNING idINSERT ... OUTPUT INSERTED.id VALUES ...RETURNING id INTO :new_idRETURNING id (3.35+) or last_insert_rowid()
Insert or update (upsert)INSERT ... AS new ON DUPLICATE KEY UPDATE city = new.cityINSERT ... ON CONFLICT (id) DO UPDATE SET city = EXCLUDED.cityMERGE 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 result

MySQL 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

TaskMySQL / MariaDBPostgreSQLSQL ServerOracleSQLite
Auto-increment idINT AUTO_INCREMENT PRIMARY KEYINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY (or SERIAL)INT IDENTITY(1,1) PRIMARY KEYNUMBER GENERATED ALWAYS AS IDENTITY (12c+)INTEGER PRIMARY KEY
True / falseBOOLEAN (stored as TINYINT(1)), TRUE / FALSEBOOLEAN, TRUE / FALSEBIT, 1 / 0BOOLEAN in 23ai; before that NUMBER(1), 1 / 0INTEGER, 1 / 0 (TRUE and FALSE accepted, stored as 1 and 0)
Short textVARCHAR(255)VARCHAR(255) or TEXTNVARCHAR(255) for UnicodeVARCHAR2(255)TEXT
Long textTEXT / LONGTEXTTEXTNVARCHAR(MAX)CLOBTEXT
Date and timeDATETIMETIMESTAMPDATETIME2TIMESTAMP (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

TaskMySQL / MariaDBPostgreSQLSQL ServerOracleSQLite
NowNOW()NOW()SYSDATETIME() or GETDATE()SYSTIMESTAMP or SYSDATEdatetime('now') (UTC)
TodayCURDATE()CURRENT_DATECAST(GETDATE() AS date)TRUNC(SYSDATE)date('now')
Add 7 daysd + INTERVAL 7 DAYd + INTERVAL '7 days'DATEADD(day, 7, d)d + 7date(d, '+7 days')
Days between two datesDATEDIFF(d2, d1)d2 - d1 (for DATE values)DATEDIFF(day, d1, d2)d2 - d1julianday(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.

TaskMySQL / MariaDBPostgreSQLSQL ServerOracleSQLite
SELECT 7 / 23.5000333.53
'Sara' = 'sara' (default setup)True (case-insensitive collation)FalseTrue (case-insensitive collation)FalseFalse (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 NULLFalseFalseFalseTrue: an empty string is NULLFalse
  • Integer division. PostgreSQL, SQL Server and SQLite drop the fraction when both numbers are integers (tested: 7/2 returned 3 in PostgreSQL and SQLite). Write 7/2.0 or cast one side to a decimal. MySQL's / always returns a decimal; use DIV for whole numbers.
  • NULL in a concatenation. In PostgreSQL and SQLite, name || ' - ' || city returned NULL for the row whose city was NULL, while PostgreSQL's CONCAT returned "Zoe - ". Wrap nullable columns in COALESCE(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 has ILIKE (tested: 'Sara' ILIKE 'sara' is true).
  • Empty strings in Oracle. Oracle stores '' as NULL, so WHERE name = '' never matches. Use WHERE 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.

Sources