WeCodeAcademy

SQL Reference

SQL statements, clauses, operators and functions. Examples run on the practice shop database.

49 of 49
KeywordTypeDescription
SELECTStatementChooses columns to return.
SELECT DISTINCTStatementReturns only different values.
FROMClauseNames the table to read.
WHEREClauseFilters rows.
ORDER BYClauseSorts the result.
LIMITClauseLimits the number of rows.
OFFSETClauseSkips rows before returning.
GROUP BYClauseGroups rows for aggregates.
HAVINGClauseFilters groups.
ASClauseGives a column or table an alias.
ANDOperatorBoth conditions must be true.
OROperatorEither condition may be true.
NOTOperatorReverses a condition.
INOperatorMatches any value in a list.
BETWEENOperatorMatches a range, inclusive.
LIKEOperatorMatches a text pattern.
IS NULLOperatorTests for no value.
COUNT()FunctionCounts rows.
SUM()FunctionAdds up numbers.
AVG()FunctionThe average.
MIN()FunctionThe smallest value.
MAX()FunctionThe largest value.
ROUND()FunctionRounds a number.
UPPER()FunctionUpper-case text.
LOWER()FunctionLower-case text.
LENGTH()FunctionThe number of characters.
SUBSTR()FunctionPart of a string.
REPLACE()FunctionReplaces text.
COALESCE()FunctionThe first value that is not NULL.
CASEFunctionIf-then logic inside a query.
CAST()FunctionConverts a value to another type.
INNER JOINJoinRows with a match in both tables.
LEFT JOINJoinAll rows from the left table, matched where possible.
CROSS JOINJoinEvery combination of rows.
UNIONSetCombines results, removing duplicates.
UNION ALLSetCombines results, keeping duplicates.
EXISTSSubqueryTrue if a subquery returns rows.
SubquerySubqueryA query inside another query.
INSERT INTOStatementAdds rows.
UPDATEStatementChanges rows.
DELETEStatementRemoves rows.
CREATE TABLEStatementCreates a table.
ALTER TABLEStatementChanges a table.
DROP TABLEStatementDeletes a table.
CREATE INDEXStatementSpeeds up lookups on a column.
PRIMARY KEYConstraintUniquely identifies each row.
NOT NULLConstraintThe column must have a value.
DEFAULTConstraintA value used when none is given.
UNIQUEConstraintNo two rows may share the value.