The SQL Language: Statement Types, Standards and Dialects
What SQL is, where it came from and how it's organized: the five families of statements, the ISO standard from SQL-86 to SQL:2023, how Oracle, SQL Server, PostgreSQL, MySQL and SQLite differ, the rules for quotes, case and comments, and a readable coding style.
kvi5hnuCode Sprout team member12 min readOn this page
SQL (Structured Query Language) is the language every relational database understands. You use it to define tables, add and change data, ask questions of the data, control who can see what, and group changes into transactions. People pronounce it "S-Q-L" or "sequel". Both are fine.
SQL is declarative. You describe the result you want, not the steps to compute it:
SELECT name, city
FROM customers
WHERE city = 'Pune'
ORDER BY name;
This query doesn't say whether to scan the whole table or use an index, or which sorting algorithm to use. The DBMS's optimizer decides that, and it may choose differently tomorrow if the data changes. Article 67 shows how to look at its decisions.
The five families of statements
SQL statements fall into five groups. You'll meet each one in this course.

| Family | Purpose | Statements | Covered in |
|---|---|---|---|
| Query | read data | SELECT | Parts 2–6, 9 |
| DML, data manipulation language | add, change and remove rows | INSERT, UPDATE, DELETE, MERGE | Part 7 |
| DDL, data definition language | create and change database objects | CREATE, ALTER, DROP, TRUNCATE | Part 11 |
| DCL, data control language | control access | GRANT, REVOKE | Part 12 |
| TCL, transaction control language | make changes permanent or undo them | COMMIT, ROLLBACK, SAVEPOINT | Part 12 |
Many references count SELECT as part of DML, since it works on data rather than definitions. The labels are only a convention, so don't worry about the exact boundaries.
Here's one statement of each kind, to give you a feel for the language. You don't need to understand the details yet:
CREATE TABLE stores ( -- DDL: define a table
store_id INTEGER PRIMARY KEY,
city VARCHAR(40) NOT NULL
);
INSERT INTO stores (store_id, city) -- DML: add a row
VALUES (1, 'Leeds');
UPDATE stores SET city = 'York' -- DML: change rows
WHERE store_id = 1;
SELECT store_id, city FROM stores; -- query: read rows
GRANT SELECT ON stores TO reporting_role; -- DCL: allow a role to read
COMMIT; -- TCL: make the changes permanent
Other database objects
Tables hold the data, but a database contains other kinds of objects too. Each one is created with DDL:
- A view is a stored query that you can select from as if it were a table (article 56).
- An index is a lookup structure that speeds up searches on some columns (article 55).
- A sequence or identity column generates key values (article 54).
- Stored procedures and functions are named programs stored in the database. Triggers run automatically when rows change (Part 13).
- Users and roles represent who can connect and what they're allowed to do (article 58).
A short history, and the standard
- 1970. Edgar F. Codd publishes the relational model (article 1).
- 1974. At IBM, Donald Chamberlin and Raymond Boyce design SEQUEL, later renamed SQL, for the System R research project.
- 1979. Relational Software, Inc., the company that became Oracle, ships the first commercial SQL database. IBM follows with SQL/DS (1981) and DB2 (1983).
- 1986–1987. ANSI and then ISO publish the first SQL standard. Since then, the ISO/IEC 9075 standard has been revised many times.
The editions you'll hear about, and the main features each one brought:
| Edition | Notable additions |
|---|---|
| SQL-92 | JOIN ... ON syntax, outer joins, CASE, CAST, many data types. Most "basic SQL" dates from here. |
| SQL | recursive queries (WITH RECURSIVE), triggers, BOOLEAN, user-defined types |
| SQL | window functions, MERGE, sequences and identity columns, XML |
| SQL | FETCH FIRST n ROWS ONLY, TRUNCATE, INSTEAD OF triggers |
| SQL | temporal (system-versioned) tables |
| SQL | JSON functions, row pattern recognition (MATCH_RECOGNIZE), LISTAGG |
| SQL | multidimensional arrays (a separate part, SQL/MDA) |
| SQL | property-graph queries (SQL/PGQ), a native JSON type and JSON dot notation, GREATEST/LEAST, ANY_VALUE, UNIQUE NULLS NOT DISTINCT, string padding, multi-character TRIM, underscores in numeric literals |
Two facts about the standard matter in practice:
- No product implements all of it, and most of the standard consists of optional features. Each vendor implements a large common core plus its own choice of extras.
- Every product adds non-standard features. These are often useful, such as
LIMITin PostgreSQL and MySQL,TOPin SQL Server andCONNECT BYin Oracle, but they won't run elsewhere.
So "SQL" in practice means a family of dialects that share most of their syntax. This course teaches standard SQL wherever it's widely supported, and calls out the dialect differences you'll actually trip over.
The major dialects
| Oracle | SQL Server | PostgreSQL | MySQL | SQLite | |
|---|---|---|---|---|---|
| Typical use | large enterprise systems | enterprise and Windows-centric shops | general purpose, open source | web applications, open source | embedded in apps, phones, browsers, tests |
| Procedural language | PL/SQL | T-SQL | PL/pgSQL (plus others) | stored programs (SQL/PSM style) | none (use the host language) |
| First n rows | FETCH FIRST n ROWS ONLY | TOP (n) or OFFSET ... FETCH | LIMIT n or FETCH FIRST | LIMIT n | LIMIT n |
| Concatenate strings | || | + or CONCAT (|| too since 2025) | || | CONCAT() | || |
| Quote an identifier | "name" | [name] or "name" | "name" | `name` | "name" |
| Unquoted names are | folded to UPPERCASE | kept; case sensitivity depends on collation | folded to lowercase | column names case-insensitive; table names depend on the OS | case-insensitive |
| Auto-generated key | GENERATED AS IDENTITY | IDENTITY(1,1) | GENERATED AS IDENTITY | AUTO_INCREMENT | INTEGER PRIMARY KEY |
| Can DDL be rolled back? | no (DDL commits) | yes | yes | no (DDL commits) | yes |
A few differences deserve a special warning, because they change results silently instead of raising an error:
- In MySQL,
||means logical OR unless thePIPES_AS_CONCATmode is set.SELECT 'a' || 'b'returns0there, not'ab'. - In MySQL, double quotes make a string unless the
ANSI_QUOTESmode is set.SELECT "name" FROM treturns the wordnameon every row. - In Oracle, an empty string
''is NULL. In every other database it's an ordinary zero-length string. - In PostgreSQL,
CREATE TABLE Gear (ItemName ...)createsgearanditemname. If you later quote"ItemName", PostgreSQL reports that the column doesn't exist. Oracle does the same thing in uppercase.
Lexical rules: case, quotes, comments and semicolons
These rules hold in almost every dialect:
- Keywords are case-insensitive.
SELECT,selectandSelectare the same. - Unquoted identifiers (table and column names) are case-insensitive in the standard. Products differ in how they store them, as the table above shows. The portable habit is to use lowercase names with underscores, like
order_date, and never quote them. - Single quotes make a string literal:
'Leeds'. To put a quote inside a string, double it:'it''s'. - Double quotes make a quoted identifier:
"list price". A quoted name may contain spaces or reserved words, and it's case-sensitive. Avoid needing one. - Comments are
-- to the end of the lineor/* across lines */. MySQL requires a space after--. - Whitespace and line breaks don't matter, so lay statements out for readability.
- A semicolon ends a statement. It's required when you run several statements in one script. Most tools also accept a single statement without one.
The runnable example below shows these rules in PostgreSQL:
CREATE TABLE Products (
Product_ID INTEGER PRIMARY KEY,
Name VARCHAR(40) NOT NULL,
"List Price" DECIMAL(8, 2) -- a quoted identifier may contain a space
);
INSERT INTO products VALUES (1, 'Trail tent', 249.99), (2, 'Head torch', 34.50);
-- 1. Keywords and unquoted names are case-insensitive; layout doesn't matter
select NAME from PRODUCTS where product_id = 1;
-- 2. Single quotes make a string; double quotes name a column
SELECT name,
'List Price' AS a_string, /* a literal */
"List Price" AS the_column,
'it''s cheap' AS escaped -- two quotes inside a literal
FROM products
ORDER BY product_id;
-- 3. PostgreSQL stored the unquoted names in lowercase, so this quoted name doesn't exist
SELECT "Name" FROM products;
name
------------
Trail tent
(1 row)
name | a_string | the_column | escaped
------------+------------+------------+------------
Trail tent | List Price | 249.99 | it's cheap
Head torch | List Price | 34.50 | it's cheap
(2 rows)
psql:/workspace/solution.sql:20: ERROR: column "Name" does not exist
LINE 1: SELECT "Name" FROM products;
^
HINT: Perhaps you meant to reference the column "products.name".
Notice three things in the output:
- The first query found the table and column even though the names were typed in a different case. The header shows
namein lowercase, because that's how PostgreSQL stored the unquotedName. 'List Price'in single quotes is just text, repeated on every row."List Price"in double quotes is the column, so it returns the prices.- The last query failed.
CREATE TABLEfolded the unquotedNametoname, so the quoted, case-sensitive"Name"doesn't exist. TheHINTline even suggests the right column. Quoted identifiers have to be quoted the same way every time, which is the main reason to avoid them.
Some databases are more forgiving, and that isn't always a good thing. In SQLite, a double-quoted word that matches no column is quietly treated as a string, for compatibility with old MySQL code. So a misspelled column name gives you a wrong answer instead of an error. Always use single quotes for strings.
A readable coding style
SQL doesn't care about layout, but people do. Most teams follow a style like this:
- Write keywords in uppercase and names in lowercase, so the structure stands out. Some teams use all lowercase. Either is fine if it's consistent.
- Start each main clause (
SELECT,FROM,WHERE,GROUP BY,ORDER BY) on a new line. - Put long column lists one per line, and indent continuation lines.
- Use short, meaningful table aliases (
cfor customers,ofor orders). - Use comments to explain why a condition exists, not what the SQL obviously does.
-- Hard to read
select c.name,o.order_id,o.total from customers c join orders o on o.customer_id=c.customer_id where o.total>100 order by o.total desc;
-- Easy to read
SELECT c.name,
o.order_id,
o.total
FROM customers AS c
JOIN orders AS o
ON o.customer_id = c.customer_id
WHERE o.total > 100 -- free-shipping threshold
ORDER BY o.total DESC;
Formatters such as sqlfluff (a linter and formatter) or the formatter built into your editor can apply a style automatically.
Procedural extensions
Plain SQL has no variables, loops or IF statements in the usual sense. Each statement is a single description of a result or a change. For logic that needs steps, every major product adds a procedural language that runs inside the database: PL/SQL in Oracle, T-SQL in SQL Server, PL/pgSQL in PostgreSQL, and MySQL's stored-program language. You use these languages to write stored procedures, functions and triggers. Part 13 teaches them with PL/pgSQL as the main example, with PL/SQL and T-SQL equivalents.
What's current
- SQL is the newest edition of the standard. The next revision is in progress, but no new edition has been published yet.
- Recent dialect changes:
- Oracle AI Database 26ai (and 23ai before it) brought Oracle much closer to the standard and to other products. It added a SQL
BOOLEANtype,SELECTwithoutFROM DUAL,IF [NOT] EXISTSin DDL, column aliases inGROUP BY, andGROUP BY ALL. - SQL Server 2025 added native regular expressions (
REGEXP_LIKEand friends) and the||concatenation operator. - PostgreSQL has accepted numeric literals with underscores, such as
1_000_000, since version 16.
- Oracle AI Database 26ai (and 23ai before it) brought Oracle much closer to the standard and to other products. It added a SQL
- Property-graph queries (SQL/PGQ) are available in Oracle 23ai and later. PostgreSQL developed support during the version 19 cycle, but removed it before the final release.
Common questions
Which dialect should I learn first? Any of them. Roughly 80% of everyday SQL is identical everywhere. PostgreSQL is the closest to the standard, which makes it a good reference point. After that, learning a second dialect is mostly a matter of looking up a few function names and syntax differences.
Is SQL case-sensitive?
Keywords never are. Unquoted identifiers are case-insensitive, though products differ in how they store them. String comparisons are a separate matter: 'Leeds' = 'leeds' is false in PostgreSQL and Oracle by default, but true in MySQL and SQL Server with their default collations. Article 36 covers collations.
Why do some people write SQL keywords in uppercase? Only for readability: it separates the language from your table and column names. The database doesn't care.
Is the semicolon required?
It's required to separate statements in a script. Tools and drivers usually accept one statement without it. In SQL Server, some statements, such as one placed before a CTE or a THROW, need the previous statement to end with a semicolon, so it's a good habit to always write one.
Do I need to learn the standard, or just my product?
Learn your product's dialect, but prefer the standard form when your product supports both, such as FETCH FIRST and COALESCE over vendor-only spellings. Standard SQL is easier to move between products and easier for other people to read.
What's the difference between SQL and MySQL? SQL is the language. MySQL is one database product that implements a dialect of it, like PostgreSQL, Oracle and SQL Server do.
Summary
- SQL is a declarative language: you describe the result, and the optimizer chooses how to compute it.
- Statements fall into queries, DML (change rows), DDL (define objects), DCL (permissions) and TCL (transactions).
- The ISO standard has evolved from SQL-86 to SQL. Every product implements a large common core, a different subset of the optional features, and its own extensions.
- The biggest everyday dialect differences are row limiting, string concatenation, identifier quoting and case folding, key generation, and whether DDL can be rolled back.
- Use single quotes for strings and double quotes only for identifiers. Prefer lowercase, unquoted names.
- Lay out queries one clause per line, with meaningful aliases and comments that explain why.
Practice questions
Classify each statement as query, DML, DDL, DCL or TCL: TRUNCATE TABLE logs, MERGE INTO stock ..., REVOKE UPDATE ON orders FROM clerk, ROLLBACK, ALTER TABLE orders ADD note VARCHAR(200).
Answer
TRUNCATE is DDL, even though it removes rows: it works on the table as a whole, and in several products it can't be rolled back. MERGE is DML. REVOKE is DCL. ROLLBACK is TCL. ALTER TABLE is DDL.
This script works in SQLite but fails in PostgreSQL with "column does not exist". Why?
CREATE TABLE Gear (ItemName VARCHAR(20));
SELECT "ItemName" FROM Gear;
Answer
PostgreSQL folds unquoted identifiers to lowercase, so the table actually has a column named itemname. The quoted "ItemName" is case-sensitive and asks for a column with capital letters, which doesn't exist. SQLite treats identifiers case-insensitively, so it finds the column. The fix is to stop quoting: SELECT ItemName FROM Gear works everywhere.
A developer moves a query from PostgreSQL to MySQL. It contains SELECT first_name || ' ' || last_name AS full_name. What does MySQL return, and how should the query be written to work in both?
Answer
With default settings, MySQL treats || as logical OR. It converts the strings to numbers (mostly 0) and returns 0 or 1 instead of a name, with only a warning. CONCAT(first_name, ' ', last_name) works in MySQL, PostgreSQL, Oracle (with two arguments at a time, or nested), and SQL Server. Article 36 covers the NULL-handling differences between || and CONCAT.
Why is SELECT "Pune" a bad way to write a string literal, even in products that accept it?
Answer
In standard SQL, double quotes name an identifier, so most databases will look for a column called Pune and fail. MySQL (without ANSI_QUOTES) and SQLite accept it as a string, which hides mistakes: in SQLite, a misspelled column name in double quotes turns into a string instead of raising an error. Single quotes always mean a string.
Previous: Relational Databases Explained: Tables, Rows, Columns, Primary Keys and Foreign Keys

More in SQL Course
Quiz: SQL Dialect Differences (PostgreSQL, MySQL, SQL Server, Oracle, SQLite)
Twenty-four questions on how the major SQL databases differ: limiting rows, concatenation, empty strings, identifier case, upserts, identity columns, transactional DDL, error handling, isolation defaults, booleans, set operations, RETURNING, dates and typing.
Quiz: SQL Delicate Details
Twenty-five questions on SQL's subtle corners: NULLs in aggregates, IN and CHECK, sort order of NULLs, rounding, CHAR padding, window frame defaults, identity gaps, LIKE escapes, empty groups, set operations and multi-column updates.
Quiz: SQL Interview Questions
Thirty SQL questions of the kind asked in developer and analyst interviews: WHERE vs HAVING, DELETE vs TRUNCATE, keys, joins, duplicates, Nth-highest values, window functions, ACID, isolation, locking, indexes, views, procedures and performance.
Quiz: SQL Course Final Exam (All 15 Parts)
The final exam for the SQL course: thirty questions across all fifteen parts, from query processing, NULLs, joins and aggregation through windows, data changes, types, design, indexes, security, transactions, procedural SQL and tuning.
Discussion
Sign in to ask a question or share what you learned.