SQL dialect comparison
One task per page, written for SQL Server, PostgreSQL, MySQL, SQLite and Oracle. Each page gives you working SQL for every engine, a note on where they part ways, and a verdict on what survives a port and what has to be rewritten.
100 operations in 6 groups, five engines each.
Querying
Filtering, joining, paging and shaping result sets.
-
Row paging: LIMIT, TOP, OFFSET-FETCH and ROWNUM
Five engines, two spellings of "give me rows 21 to 30", plus Oracle's old ROWNUM wrapper.
-
First N rows: TOP vs LIMIT vs FETCH FIRST
The same query written three ways, depending on the engine.
-
First N rows per group: ROW_NUMBER vs DISTINCT ON
One window-function query that runs everywhere, plus PostgreSQL's DISTINCT ON shortcut for one row per group.
-
DISTINCT on an expression
DISTINCT works on computed values the same way it works on columns.
-
Case-insensitive string comparison
Whether = ignores case depends entirely on the column's collation.
-
String concatenation in SELECT: || vs + vs CONCAT
Same task, three operators, and the NULL rules differ between them.
-
NULL-safe equality: IS NOT DISTINCT FROM, <=> and IS
NULL = NULL is unknown, not true, unless you use a null-safe operator.
-
Conditional expressions: CASE, IIF, IF and DECODE
CASE is everywhere; IIF, IF and DECODE are the local shortcuts.
-
Replacing NULL in output: COALESCE, ISNULL, NVL, IFNULL
COALESCE everywhere; ISNULL, IFNULL and NVL are the same idea with local names.
-
Pattern matching with LIKE and ESCAPE
% and _ are wildcards until you declare an escape character, and backslash is the worst choice for one.
-
Regular expression matching: ~, REGEXP and REGEXP_LIKE
Four engines ship regex today, SQL Server only since 2025; SQLite leaves it to the application.
-
Escaping single quotes in string literals
Doubling the quote works everywhere; three engines offer nicer ways out.
-
Sorting with COALESCE in ORDER BY
Fold NULL into the value order, or park it deliberately.
-
Custom sort order: CASE, FIELD and DECODE
Alphabetical order is wrong for statuses; map them to a rank instead.
-
Sorting NULLs first or last
Three engines support the keywords; two need a sort-key trick.
-
Numbering rows: ROW_NUMBER, ROWNUM and rowid
One portable window function, and two Oracle and SQLite features that look similar but do something else.
-
Random sample of rows
ORDER BY random() works on every engine and gets slower with every row you add.
-
Excluding rows: NOT IN vs NOT EXISTS vs LEFT JOIN
NOT IN has a NULL trap that silently empties your result.
-
Date difference filters in WHERE
Compute the cutoff first, then compare. Don't wrap the column in a function.
-
Filtering by year or month without losing the index
YEAR() or EXTRACT() on the column hides it from its index. Rewrite as a range.
-
Timestamp range filters: half-open intervals
BETWEEN with a date-only upper bound keeps midnight and drops the rest of the day.
-
Implicit casts in comparisons
Four engines convert silently, one refuses, and the conversions differ.
-
Table alias syntax: where AS is optional (and where it fails)
AS is optional almost everywhere, and a syntax error in one place.
-
SELECT INTO vs CREATE TEMP TABLE AS
SQL Server says SELECT INTO, three engines say CREATE TEMP TABLE AS, and Oracle needs a special prefix.
-
CTE basics: WITH … AS across dialects
WITH works in all five engines; the details around it don't.
-
Concatenate a number to a string in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
CONCAT('Order ', 42) runs on all five engines. The operators are where they split.
-
Regular expression replace in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
PostgreSQL, MySQL and Oracle have had it for years, SQL Server added it in 2025, and SQLite's core still has none.
Inserting & updating
Adding, changing and removing rows, including upserts.
-
Upsert: insert or update in one statement
Change the row if it is already there, insert it if it is not: the statement every engine spells differently.
-
MERGE: match, update, insert and delete
One pass over a source table: update what matches, insert what does not, delete what should be gone.
-
Get the id of the row you just inserted
You inserted the row; now get back the key the engine picked for it.
-
Insert several rows in one statement
One round trip, many rows: the VALUES list that is a one-liner everywhere except older Oracle.
-
Insert rows copied from another table
The most portable statement in SQL: copy rows from one table into another in a single statement.
-
UPDATE with a join to another table
Set a column based on data in a different table: three clause orders and a subquery fallback.
-
Update from an aggregate on the same table
Recompute a column from a GROUP BY over the very table you are updating.
-
DELETE rows matched in another table
Remove the orders of deleted customers: two tables, one DELETE, four syntaxes.
-
Delete only the first N rows
Prune a log table 100 rows at a time: the statement only MySQL writes natively.
-
TRUNCATE vs DELETE: emptying a table
Two ways to empty a table that differ in speed, triggers, identity counters and rollback.
-
Insert an explicit id into an identity column
Migrating data with its original ids: three engines make you ask first, two just accept the value.
-
How many rows one INSERT can take
Every engine caps a single INSERT somewhere. Here is where the ceilings are.
Tables & schema
Creating and changing tables, constraints and views.
-
Eine Spalte zu einer bestehenden Tabelle hinzufügen
The most common ALTER: extend the table without losing data.
-
Drop a column from a table
Remove a column and its data: trivial in four engines, sometimes a rebuild in SQLite.
-
Rename a column
A metadata-only rename, if your engine has the standard syntax.
-
Rename a table
Point a new name at the same table, and swap two tables' names without a gap.
-
Change a column's type
Convert a column's data to a new type in place, with PostgreSQL's USING or the engine's implicit cast.
-
Set or remove a column default
Defaults are cheap to change, except where they are constraints or where they are frozen in the CREATE TABLE.
-
Add a foreign key or check constraint
Wire tables together or give them a rule: one ALTER, unless you are on SQLite.
-
Auto-incrementing primary keys
Five engines, five spellings of the column that numbers itself.
-
Build an index without blocking writes
Indexes on live tables: keep writes flowing while the index builds.
-
Comment on a table or column
Store documentation with the schema so tools and later readers can find it.
-
Create a schema (namespace)
Namespaces for tables: schemas, or whatever each engine calls the idea.
-
Temporary tables for session work
Scratch tables only your session can see, for staging, deduplication and multi-step queries.
-
Generated / computed columns
Columns the engine computes from other columns, stored on write or computed on read.
Types & casting
Declaring types and converting between them.
-
Cast syntax in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
CAST runs on all five engines; the native forms add format masks, style codes or a shorter spelling.
-
Cast text to a number in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Text '42' becomes 42 everywhere, but 'abc' raises an error in three engines and quietly becomes 0 in two.
-
Convert a number to formatted text in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Five engines, four different formatting idioms for the same 1,234,567.89.
-
Safe cast that returns NULL instead of an error in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
A plain CAST of 'abc' errors in SQL Server, PostgreSQL and Oracle and quietly returns 0 in MySQL and SQLite.
-
Parse text into a date in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
ISO format is the universal language; every other layout needs engine-specific parsing.
-
Format a date as text in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
The same format call does not translate across engines: the masks themselves are different languages.
-
Boolean literals: TRUE, 1 and 'Y' in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
TRUE is a keyword in four engines, but only PostgreSQL and Oracle 23ai back it with a real type. SQL Server has no TRUE at all.
-
Integer and decimal division in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
The most common silent bug when porting SQL: three engines truncate, two do not.
-
NULL versus empty string in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
In Oracle, '' IS NULL is true. Everywhere else it is false. That one fact rewrites your WHERE clauses.
-
Add days to a date in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Five engines, five spellings of 'a week from today'.
-
Add months to a date in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Jan 31 plus one month is Feb 28 in four engines, Mar 3 in SQLite, and an error with Oracle's INTERVAL form.
-
Get the first day of the month in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
A staple of reporting SQL, computed five different ways.
-
Get the last day of the month in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Three engines have a named function; PostgreSQL and SQLite make you derive it.
-
Truncate a date to day, month or year in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Grouping by month starts with truncation; MySQL and pre-2022 SQL Server make you build the result by hand.
-
Get the Unix timestamp of a date in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Three engines have a function for it; in SQL Server and Oracle you count from 1970 yourself.
-
Convert a Unix timestamp to a date in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
The inverse of extract-epoch, and just as engine-specific.
-
Convert a timestamp to another timezone in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Named zones versus fixed offsets, and which engines know the difference at all.
-
Interval literals for date arithmetic in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Two engines have real interval types; three fake it with functions and modifiers.
-
Current timestamp and its precision in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
The now() you call is not always the now you think: rounding and transaction freezing both apply.
-
Generate a UUID in SQL in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Four named functions with different versions and shapes, plus one engine that makes you roll your own.
-
Column types for UUIDs and GUIDs in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Where the UUID can be a real type, and where it is 16 bytes wearing a costume.
-
CHAR versus VARCHAR semantics in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
Blank-padding is invisible until a join compares CHAR to VARCHAR and stops matching.
-
Binary and blob hex literals in SQL Server, PostgreSQL, MySQL, SQLite and Oracle
The same four bytes, four spellings, and the SQL Server form is not even quoted.
Indizes
Creating, covering, partial and full-text indexes.
-
CREATE INDEX in every SQL dialect
The bread-and-butter index statement: nearly identical everywhere, with a few differences in naming and locking.
-
CREATE UNIQUE INDEX in every SQL dialect
A unique index both speeds up lookups and rejects duplicate values. Syntax is universal; NULL handling is where engines disagree.
-
Covering indexes and INCLUDE columns in every SQL dialect
A covering index answers a query without touching the table. SQL Server and PostgreSQL have an INCLUDE clause that keeps extra columns out of the key; the rest use composite indexes.
-
Partial (filtered) indexes in every SQL dialect
A partial index covers only rows matching a WHERE clause, keeping it small and fast when you always filter the same way.
-
Indexes on expressions like LOWER(col) in every SQL dialect
An expression index stores a function result instead of the raw column, which makes WHERE LOWER(email) = ? use an index.
-
DESC in index definitions across every SQL dialect
A descending index reverses the stored order of a column, letting ORDER BY a ASC, b DESC walk the index without a sort step.
-
Full-text search basics in every SQL dialect
Full-text search indexes words so LIKE '%term%' scans give way to real relevance searches. Every engine has one, and every engine spells it differently.
-
Column-prefix indexes in every SQL dialect
A prefix index stores just the first N characters of a varchar, cutting index size dramatically on long text columns.
-
DROP INDEX in every SQL dialect
Dropping an index is nearly universal, with one twist: SQL Server and MySQL require the table name in the statement.
-
REINDEX and ALTER INDEX REBUILD in every SQL dialect
Indexes bloat after churn. Each engine has its own rebuild verb, and one of them (MySQL) rebuilds the whole table instead.
Sessions & admin
Transactions, locking, sessions and day-to-day administration.
-
Explicit transactions in every SQL dialect
The core transaction statements: BEGIN, COMMIT and ROLLBACK, with Oracle as the odd one out since its transactions start implicitly.
-
SAVEPOINT and ROLLBACK TO in every SQL dialect
Savepoints let you undo the last steps of a transaction without discarding everything, the standard tool for per-row error recovery in bulk loads.
-
SET TRANSACTION ISOLATION LEVEL in every SQL dialect
Isolation levels trade concurrency for correctness: dirty reads, non-repeatable reads and phantoms shift between levels.
-
SELECT FOR UPDATE and SQL Server's UPDLOCK in every SQL dialect
Read rows with an intent to update and other writers will wait: the pessimistic locking pattern for queues and balance updates.
-
Advisory and application locks in every SQL dialect
Application locks let code coordinate across servers through the database: lock a name, do the work, release.
-
Lock wait and lock timeouts in every SQL dialect
A lock timeout keeps one blocked statement from freezing a queue behind it. Units differ: milliseconds in SQL Server and SQLite (and PostgreSQL without a unit), seconds in MySQL and Oracle.
-
Finding deadlock victims and blocked sessions in every SQL dialect
When transactions block each other, the engine kills one victim and logs the evidence. Here is where that evidence lives in each engine.
-
KILL, pg_terminate_backend and friends in every SQL dialect
When a session holds locks or burns CPU and nothing else works, terminate it. The verbs differ per engine.
-
Current user, database and session id in every SQL dialect
The identity card query: who am I logged in as, where am I, and what is my session id.
-
SELECT @@VERSION and version() in every SQL dialect
The first thing any support engineer asks for: exact engine and version. Every engine has a one-liner.
-
SHOW PROCESSLIST and session views in every SQL dialect
The who-is-connected view, including state and the current statement, needed before you kill anything.
-
Finding a session's last (or current) SQL in every dialect
What did that session just run? Useful when debugging a support ticket or a stuck connection.
-
Turning autocommit on or off in every SQL dialect
Autocommit on means every statement is its own transaction. Turning it off groups statements until you COMMIT.
-
Disabling and enabling triggers in every SQL dialect
Triggers run for every row or statement of a bulk load. SQL Server, PostgreSQL and Oracle can switch them off; MySQL and SQLite cannot.
-
Maintenance commands: VACUUM, ANALYZE, OPTIMIZE in every dialect
The periodic-housekeeping commands: reclaim dead space and refresh the statistics the optimizer plans with.
Nothing matches
Try the keyword an engine uses (MERGE, ROWNUM, ILIKE) or a plain word like “paging”.
Switch engines without relearning SQL
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.