Dialect Differences Cheat Sheet
The same SQL task can be written differently in each database, and, more surprisingly, the same SQL can behave differently. LIMIT 2 versus TOP 2 is easy to spot: the query simply fails on the wrong database. The quieter differences are the dangerous ones. 7 / 2 is 3 in PostgreSQL and 3.5 in MySQL, and 'navika' LIKE 'Navika' is false in PostgreSQL but true in SQLite. In Oracle, an empty string is NULL. This cheat sheet compares six databases: PostgreSQL, MySQL, SQL Server, SQLite, Oracle and MS Access (legacy). Each row is marked standard when the SQL standard defines the form, or dialect when it doesn't. PostgreSQL examples run in Try it; SQLite results come from the sqlite3 shell, version 3.54; the other columns show syntax from each database's documentation.
In One Minute
- Syntax differs most for limiting rows, ids, text joining, dates, upserts and quoting names.
- Behavior differs for integer division, case sensitivity,
NULLin unique columns, empty strings, transactional DDL and default isolation. - SQLite accepts almost any value in any column unless the table is
STRICT. - Oracle treats
''asNULL; SQL Server allows only oneNULLin a unique column. - MySQL and SQL Server compare text case-insensitively by default; PostgreSQL and Oracle don't.
- When moving SQL between databases, test the behavior, not only the syntax.
Syntax: Common Tasks
| Task | PostgreSQL | MySQL | SQL Server | SQLite | Oracle | MS Access |
|---|---|---|---|---|---|---|
| First 10 rows | LIMIT 10 or FETCH FIRST 10 ROWS ONLY (standard) | LIMIT 10 | TOP 10, or OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY | LIMIT 10 | FETCH FIRST 10 ROWS ONLY (12c+) | TOP 10 |
| Skip 20, take 10 | OFFSET 20 LIMIT 10 | LIMIT 20, 10 or LIMIT 10 OFFSET 20 | OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY | LIMIT 10 OFFSET 20 | OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY | No direct form |
| Join text | a || b (standard), concat() | CONCAT(a, b) | a + b, CONCAT() | a || b | a || b, CONCAT(a, b) (two args) | a & b |
| Auto-numbered id | GENERATED ALWAYS AS IDENTITY (standard), SERIAL | AUTO_INCREMENT | IDENTITY(1, 1) | INTEGER PRIMARY KEY | GENERATED AS IDENTITY (12c+) | AUTOINCREMENT / AutoNumber |
| Quote a name | "name" (standard) | `name` | [name] or "name" | "name" | "name" | [name] |
Replace NULL | COALESCE (standard) | COALESCE, IFNULL | COALESCE, ISNULL | COALESCE, IFNULL | COALESCE, NVL | Nz() |
| If / else | CASE (standard) | CASE, IF() | CASE, IIF() | CASE, iif() | CASE, DECODE() | IIf() |
| Now | CURRENT_TIMESTAMP (standard), now() | NOW() | SYSDATETIME(), GETDATE() | datetime('now') | SYSTIMESTAMP, SYSDATE | Now() |
| Add 30 days | d + 30, d + INTERVAL '30 days' | DATE_ADD(d, INTERVAL 30 DAY) | DATEADD(day, 30, d) | date(d, '+30 days') | d + 30 | DateAdd("d", 30, d) |
| Booleans | BOOLEAN (standard) | BOOLEAN (stored as TINYINT(1)) | BIT | 0 / 1 integers | BOOLEAN (23ai), NUMBER(1) before | Yes/No |
| Upsert | INSERT ... ON CONFLICT, MERGE (standard, 15+) | INSERT ... ON DUPLICATE KEY UPDATE | MERGE | INSERT ... ON CONFLICT | MERGE | No |
| Read a JSON field | data ->> 'name', JSON_VALUE | data ->> '$.name', JSON_VALUE | JSON_VALUE(data, '$.name') | data ->> '$.name' | JSON_VALUE(data, '$.name') | No |
| Procedural language | PL/pgSQL | SQL/PSM-style procedures | T-SQL | None (use triggers or the app) | PL/SQL | VBA |
Check versions before relying on a row. Many of these arrived recently: FETCH FIRST in Oracle 12c, MERGE in PostgreSQL 15, ->> in SQLite 3.38, BOOLEAN in Oracle Database 23ai. The SQL Syntax by Database reference has copy-ready versions of each.
Behavior: Same SQL, Different Results
These are the differences that don't produce an error: the query runs everywhere, and the answers differ. Here is a small script run on PostgreSQL:
SELECT 7 / 2 AS int_div, 7 / 2.0 AS dec_div;
SELECT 'navika' LIKE 'Navika' AS like_ignores_case,
'navika' = 'Navika' AS equals;
CREATE TABLE t (n INTEGER, email TEXT UNIQUE);
INSERT INTO t VALUES ('abc', NULL);
INSERT INTO t VALUES (5, NULL);
INSERT INTO t VALUES (6, NULL);
SELECT n, email FROM t ORDER BY n; int_div | dec_div
---------+--------------------
3 | 3.5000000000000000
(1 row)
like_ignores_case | equals
-------------------+--------
f | f
(1 row)
CREATE TABLE
ERROR: invalid input syntax for type integer: "abc"
INSERT 0 1
INSERT 0 1
n | email
---+-------
5 | NULL
6 | NULL
(2 rows)And nearly the same script in SQLite 3.54, run with sqlite3 -header -column (with typeof() added to show how each value was stored):
SELECT 7 / 2 AS int_div, 7 / 2.0 AS dec_div;
SELECT 'navika' LIKE 'Navika' AS like_ignores_case,
'navika' = 'Navika' AS equals;
CREATE TABLE t (n INTEGER, email TEXT UNIQUE);
INSERT INTO t VALUES ('abc', NULL);
INSERT INTO t VALUES (5, NULL);
SELECT n, typeof(n) AS stored_as, email FROM t;int_div dec_div
------- -------
3 3.5
like_ignores_case equals
----------------- ------
1 0
n stored_as email
--- --------- -----
abc text
5 integerExplanation:
- Integer division: both print
3for7 / 2, because both integers stay integers. MySQL and Oracle would give3.5000and3.5. Write7 / 2.0orCAST(7 AS NUMERIC) / 2when you want the fraction everywhere. LIKEand case: PostgreSQL'sLIKEis case-sensitive, so'navika' LIKE 'Navika'is false (f). SQLite'sLIKEignores case for plain ASCII letters, so it's true (1). Plain=is case-sensitive in both.- Types: PostgreSQL refuses
'abc'for anINTEGERcolumn. SQLite stores it anyway, as text, because SQLite columns have a type affinity, not a strict type. A table declaredSTRICT(SQLite 3.37 and later) refuses it. NULLin a unique column: both allow severalNULLemails, becauseNULLisn't equal toNULL.
Behavior Across All Six
| Behavior | PostgreSQL | MySQL | SQL Server | SQLite | Oracle | MS Access |
|---|---|---|---|---|---|---|
7 / 2 | 3 | 3.5000 | 3 | 3 | 3.5 | 3.5 |
= on text, default setup | Case-sensitive | Case-insensitive (default collation) | Case-insensitive (default collation) | Case-sensitive | Case-sensitive | Case-insensitive |
'' (empty string) | A value | A value | A value | A value | Same as NULL | A value (when allowed) |
Several NULLs in a UNIQUE column | Allowed (unless NULLS NOT DISTINCT) | Allowed | Only one (use a filtered unique index for more) | Allowed | Allowed | Depends on the index's Ignore Nulls setting |
CREATE TABLE inside a transaction can roll back | Yes | No: DDL commits automatically | Yes | Yes | No: DDL commits automatically | Not offered in the query editor |
| Default isolation level | Read Committed | Repeatable Read (InnoDB) | Read Committed (with row versioning by default in Azure SQL Database) | Serializable | Read Committed | Not applicable |
| Primary key clusters the table | No (heap table) | Yes (InnoDB) | Yes, by default | Rowid tables cluster on the rowid | No (unless index-organized) | Not applicable |
| Time zones | TIMESTAMPTZ stores a moment | TIMESTAMP converts to UTC; DATETIME doesn't | DATETIMEOFFSET | Text or numbers; no date type | TIMESTAMP WITH TIME ZONE | None |
The four that cause the most bugs when moving between databases:
- Case sensitivity. A login check
WHERE email = 'Navika@Example.com'matchesnavika@example.comon MySQL and SQL Server defaults, but not on PostgreSQL. On PostgreSQL, comparelower(email), use thecitextextension, or a case-insensitive collation. - Oracle's empty string.
WHERE middle_name = ''never matches in Oracle, because''isNULL. UseIS NULL. - SQL Server's single
NULL. AUNIQUEemail column refuses the second student with no email. Use a filtered index:CREATE UNIQUE INDEX ... WHERE email IS NOT NULL. - Non-transactional DDL in MySQL and Oracle. A failing migration can leave its first steps applied (Schema Migrations).
Checking Which Database You're On
When in doubt, ask the database for its name and version:
| Database | Query |
|---|---|
| PostgreSQL | SELECT version(); or SHOW server_version; |
| MySQL / MariaDB | SELECT VERSION(); |
| SQL Server | SELECT @@VERSION; |
| SQLite | SELECT sqlite_version(); |
| Oracle | SELECT banner FROM v$version; |
SHOW server_version; server_version
----------------
18.7
(1 row)MariaDB and Db2
MariaDB started as a copy (fork) of MySQL in 2009 and is still close to it: the MySQL column above mostly applies. The two have drifted in newer features; for example, MariaDB has system-versioned (temporal) tables and RETURNING on INSERT and DELETE, while MySQL has neither, and their JSON implementations differ. IBM Db2 follows the standard closely: FETCH FIRST, ||, GENERATED AS IDENTITY, MERGE and SQL PL procedures.
MS Access Functions (Legacy)
MS Access uses its own function names, closer to Visual Basic than to SQL. If you meet an old Access database:
| Need | Access | Standard / PostgreSQL |
|---|---|---|
Replace NULL | Nz(x, 0) | COALESCE(x, 0) |
| If / else | IIf(cond, a, b) | CASE WHEN cond THEN a ELSE b END |
| Join text | a & b | a || b |
| Text pattern | LIKE "Nav*" | LIKE 'Nav%' |
| Today | Date() | CURRENT_DATE |
| Part of a date | Year(d), Month(d), DatePart("q", d) | EXTRACT(YEAR FROM d) |
| Format | Format(d, "yyyy-mm-dd") | to_char(d, 'YYYY-MM-DD') |
Access uses * and ? as wildcards in its own query editor (and % and _ in ANSI-92 mode), #2025-12-03# for date literals, and double quotes for text.
Common Mistakes
Testing on one database and deploying on another. The syntax may match while the answers don't. Test on the engine you'll run.
Relying on case-insensitive comparisons. They are a collation setting, not SQL. Normalize case explicitly when it matters.
Using '' and NULL interchangeably. Oracle treats them as the same; nobody else does.
Integer division surprises. count(*) / 3 loses the fraction in PostgreSQL, SQL Server and SQLite. Cast first.
Assuming DDL rolls back. MySQL and Oracle commit CREATE, ALTER and DROP immediately.
Interview Corner
What does SELECT 7 / 2 return?
It depends on the database: 3 in PostgreSQL, SQL Server and SQLite, which keep integer division; 3.5000 in MySQL and 3.5 in Oracle. Cast one side to a decimal type to get the fraction everywhere.
How does Oracle treat an empty string?
As NULL. '' IS NULL is true in Oracle, so WHERE col = '' never matches. Other major databases treat '' as a real, empty value.
How do NULLs behave in a UNIQUE column?
Most databases allow many NULLs because NULL isn't equal to NULL. SQL Server allows only one unless you use a filtered unique index; PostgreSQL 15+ can refuse duplicates with NULLS NOT DISTINCT.
Is text comparison case-sensitive?
It depends on the collation. PostgreSQL and Oracle are case-sensitive by default; MySQL and SQL Server defaults are case-insensitive. SQLite's = is case-sensitive, but its LIKE ignores ASCII case.
Practice
Challenge: Make a case-insensitive search that gives the same answer on every database: find students whose first name is 'navika', however it was typed, using only standard SQL.
Show solution
SELECT student_id, first_name
FROM students
WHERE LOWER(first_name) = LOWER('navika')
ORDER BY student_id; student_id | first_name
------------+------------
103 | Navika
(1 row)Lowercasing both sides makes the comparison independent of the database's collation, so it returns Navika on PostgreSQL, MySQL, SQL Server, SQLite and Oracle alike. On a big table, it needs an index on LOWER(first_name) to stay fast (Index Design).
Key Takeaways
| You want to | Portable choice |
|---|---|
| Limit rows | FETCH FIRST n ROWS ONLY (or your database's form) |
| Case-insensitive match | LOWER(col) = LOWER(value) |
| Decimal division | CAST(a AS NUMERIC) / b |
Replace NULL | COALESCE(a, b) |
| Check for "no value" | IS NULL (never = '' in Oracle) |
Was this tutorial helpful?