SQL Keywords Reference

Updated · 7 min read
easyPostgreSQL 18sqlkeywordsreferenceassessment

Every SQL keyword used in this course, in alphabetical order, with what it does and where it's taught. It covers every keyword in the common online SQL references, plus the modern ones they leave out, such as FILTER, LATERAL, MERGE and RETURNING. Use the browser's find (Ctrl+F or Cmd+F) to jump to a keyword.

KeywordWhat it doesLesson
ADDAdd a column or constraint to a tableALTER TABLE and DROP TABLE
ADD CONSTRAINTAdd a named constraint to an existing tableConstraints
ALLTrue if the comparison holds for every value of a subqueryANY and ALL
ALTERChange an existing objectALTER TABLE and DROP TABLE
ALTER COLUMNChange a column's type, default or nullabilityALTER TABLE and DROP TABLE
ALTER TABLEAdd, drop or change columns and constraintsALTER TABLE and DROP TABLE
ANDBoth conditions must be trueAND, OR and NOT
ANYTrue if the comparison holds for at least one value of a subqueryANY and ALL
ASGive a column or table an aliasAliases
ASCSort ascending (the default)ORDER BY
BACKUP DATABASESQL Server: back up a database (PostgreSQL uses pg_dump)Backup and Restore
BEGINStart a transactionTransactions
BETWEENA value within a range, both ends includedIN and BETWEEN
CASEChoose a value by conditionsCASE Expressions
CHECKA rule each row must satisfyConstraints
COLUMNUsed with ADD, ALTER, DROP and RENAMEALTER TABLE and DROP TABLE
COMMITMake a transaction's changes permanentTransactions
CONSTRAINTName a rule on a tableConstraints
CREATECreate a database objectCREATE TABLE
CREATE DATABASECreate a new databaseCreating a Database
CREATE INDEXCreate an indexIndexes
CREATE OR REPLACE VIEWCreate a view, or replace it if it existsViews
CREATE PROCEDURECreate a stored procedureStored Procedures
CREATE TABLECreate a tableCREATE TABLE
CREATE UNIQUE INDEXCreate an index that forbids duplicate valuesIndexes
CREATE VIEWCreate a saved queryViews
CROSS JOINPair every row with every rowCROSS JOIN
DATABASEUsed with CREATE and DROPCreating a Database
DEFAULTA column's value when none is givenConstraints
DELETERemove rowsDELETE
DESCSort descendingORDER BY
DISTINCTRemove duplicate rowsSELECT DISTINCT
DROPRemove an objectALTER TABLE and DROP TABLE
DROP COLUMNRemove a columnALTER TABLE and DROP TABLE
DROP CONSTRAINTRemove a constraintConstraints
DROP DATABASEDelete a database and everything in itCreating a Database
DROP DEFAULTRemove a column defaultConstraints
DROP INDEXRemove an indexIndexes
DROP TABLEDelete a table and its dataALTER TABLE and DROP TABLE
DROP VIEWRemove a viewViews
EXCEPTRows in the first query but not the second (Oracle: MINUS)INTERSECT and EXCEPT
EXEC / CALLRun a stored procedure (SQL Server EXEC; PostgreSQL and MySQL CALL)Stored Procedures
EXISTSTrue if a subquery returns any rowEXISTS
EXPLAINShow a query's planReading EXPLAIN
FETCH FIRSTStandard way to limit rowsLimiting Rows: LIMIT, TOP and FETCH
FILTERLimit an aggregate to matching rowsPivoting Data
FOREIGN KEYA column that must match a key in another tableFOREIGN KEY
FROMThe tables to readSELECT
FULL OUTER JOINKeep rows from both tables, matched or notFULL OUTER JOIN
GRANTGive privilegesUsers, Roles and Privileges
GROUP BYGroup rows for aggregatesGROUP BY
HAVINGFilter groupsHAVING
INA value in a list or subqueryIN and BETWEEN
INDEXA structure that speeds up lookupsIndexes
INNER JOINKeep only matching rowsINNER JOIN
INSERT INTOAdd rowsINSERT INTO
INSERT INTO SELECTCopy rows from a query into a tableINSERT INTO SELECT and Loading Files
INTERSECTRows in both queriesINTERSECT and EXCEPT
IS NOT NULLTest for a present valueNULL Values
IS NULLTest for a missing valueNULL Values
JOINCombine rows from tablesHow Joins Work
LATERALA subquery that can use columns from earlier tablesLATERAL Joins
LEFT JOINKeep every row from the left tableLEFT JOIN
LIKEPattern match with % and _LIKE and Wildcards
LIMITLimit rows (PostgreSQL, MySQL, SQLite)Limiting Rows: LIMIT, TOP and FETCH
MERGEInsert, update or delete rows by matching a sourceUpsert and MERGE
NOTNegate a conditionAND, OR and NOT
NOT NULLA value is requiredConstraints
NULLA missing or unknown valueNULL Values
OFFSETSkip rowsPagination
ONA join conditionHow Joins Work
ON CONFLICTPostgreSQL and SQLite upsertUpsert and MERGE
ORAt least one condition trueAND, OR and NOT
ORDER BYSort the resultORDER BY
OUTER JOINLEFT, RIGHT or FULL joinFULL OUTER JOIN
OVERDefine a window for a window functionWindow Functions
PARTITION BYSplit a window into groupsWindow Functions
PRIMARY KEYThe column(s) that identify each rowUNIQUE and PRIMARY KEY
PROCEDUREA stored routine run with CALL or EXECStored Procedures
RECURSIVEA CTE that refers to itselfRecursive CTEs
REFERENCESDeclare a foreign keyFOREIGN KEY
RETURNINGReturn columns of changed rows (PostgreSQL, SQLite)INSERT INTO
REVOKETake privileges awayUsers, Roles and Privileges
RIGHT JOINKeep every row from the right tableRIGHT JOIN
ROLLBACKUndo a transactionTransactions
ROLLUPSubtotals and a grand totalROLLUP, CUBE and GROUPING SETS
ROWNUMOracle's older way to limit rowsLimiting Rows: LIMIT, TOP and FETCH
SAVEPOINTA point inside a transaction to roll back toTransactions
SELECTRead dataSELECT
SELECT DISTINCTRead data without duplicate rowsSELECT DISTINCT
SELECT INTOCreate a table from a query (SQL Server, PostgreSQL)Copying a Table
SELECT TOPLimit rows (SQL Server, MS Access)Limiting Rows: LIMIT, TOP and FETCH
SETAssign values in UPDATE; change a settingUPDATE
TABLEUsed with CREATE, ALTER, DROP and TRUNCATECREATE TABLE
TOPLimit rows (SQL Server, MS Access)Limiting Rows: LIMIT, TOP and FETCH
TRUNCATE TABLERemove all rows quicklyDELETE
UNIONRows from both queries, duplicates removedUNION and UNION ALL
UNION ALLRows from both queries, duplicates keptUNION and UNION ALL
UNIQUENo two rows may share the valueUNIQUE and PRIMARY KEY
UPDATEChange rowsUPDATE
VALUESThe values to insertINSERT INTO
VIEWA saved queryViews
WHEREFilter rowsWHERE
WITHA common table expressionCommon Table Expressions

For the same tasks written for each database, see the SQL Syntax by Database.

Was this tutorial helpful?