SQL Syntax by Database
Most SQL is the same in every database, but the details differ: how you limit rows, generate ids, add days to a date or upsert a row. This reference lists 57 common tasks in five databases, PostgreSQL, MySQL, SQL Server, Oracle and SQLite, each marked standard (the SQL standard defines it) or dialect (each database has its own way). Pick a topic to compare all five, or pick your database to see every task in its own spelling.
How these were checked: every PostgreSQL and SQLite form on this page was run (PostgreSQL 18 and SQLite 3.54). MySQL, SQL Server and Oracle forms follow each database's current documentation (MySQL 8.4, SQL Server 2022 and later, Oracle AI Database 26ai); version notes such as "8.0.19+" mark features that older releases lack.
Browse by Topic
| Topic | What's in it |
|---|---|
| Syntax: Querying | Limiting rows, paging, case-insensitive matching, outer joins, set operators, quoting names |
| Syntax: Changing Data | Multi-row inserts, returning ids, update from another table, upserts, loading CSV files |
| Syntax: Tables and Keys | Identity columns, money, text and boolean types, keys, checks, altering tables, indexes, views |
| Syntax: Functions | Text, numbers, dates, conversion, CASE, joining values from many rows |
| Syntax: Advanced SQL | CTEs, recursion, window functions, conditional counts, subtotals, JSON, full-text search, functions |
| Syntax: Administration | Transactions, savepoints, isolation, plans, users, privileges, backups, parameters |
Browse by Database
| Database | Every task in its syntax |
|---|---|
| PostgreSQL | PostgreSQL Syntax |
| MySQL | MySQL Syntax |
| SQL Server | SQL Server Syntax |
| Oracle | Oracle Syntax |
| SQLite | SQLite Syntax |
Which Database Am I Using?
Ask the server. Each database answers with its name and version:
| Database | Query |
|---|---|
| PostgreSQL | SELECT version(); |
| MySQL / MariaDB | SELECT VERSION(); |
| SQL Server | SELECT @@VERSION; |
| Oracle | SELECT banner FROM v$version; |
| SQLite | SELECT sqlite_version(); |
The Try it examples on this site run PostgreSQL:
SELECT version() LIKE 'PostgreSQL 18%' AS is_postgresql_18;
SHOW server_version; is_postgresql_18
------------------
t
(1 row)
server_version
----------------
18.7
(1 row)Was this tutorial helpful?