SQL Syntax by Database

Updated · 2 min read

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

TopicWhat's in it
Syntax: QueryingLimiting rows, paging, case-insensitive matching, outer joins, set operators, quoting names
Syntax: Changing DataMulti-row inserts, returning ids, update from another table, upserts, loading CSV files
Syntax: Tables and KeysIdentity columns, money, text and boolean types, keys, checks, altering tables, indexes, views
Syntax: FunctionsText, numbers, dates, conversion, CASE, joining values from many rows
Syntax: Advanced SQLCTEs, recursion, window functions, conditional counts, subtotals, JSON, full-text search, functions
Syntax: AdministrationTransactions, savepoints, isolation, plans, users, privileges, backups, parameters

Browse by Database

DatabaseEvery task in its syntax
PostgreSQLPostgreSQL Syntax
MySQLMySQL Syntax
SQL ServerSQL Server Syntax
OracleOracle Syntax
SQLiteSQLite Syntax

Which Database Am I Using?

Ask the server. Each database answers with its name and version:

DatabaseQuery
PostgreSQLSELECT version();
MySQL / MariaDBSELECT VERSION();
SQL ServerSELECT @@VERSION;
OracleSELECT banner FROM v$version;
SQLiteSELECT sqlite_version();

The Try it examples on this site run PostgreSQL:

SQL▶ Try it
SELECT version() LIKE 'PostgreSQL 18%' AS is_postgresql_18;
SHOW server_version;
Output
 is_postgresql_18
------------------
 t
(1 row)
 
 server_version
----------------
 18.7
(1 row)

Was this tutorial helpful?