SELECT Statement Syntax
-
In any column expression, a wildcard like
*can be used to specify all columns, while<table name/alias>.*can be used to specify all columns from the given table. -
The
EXCLUDEfunction can be used to list columns to exclude from the wildcard expression it follows; for instance, the following can be used to select all columns from the employee table except for thessn&date_of_birthcolumns:EXCLUDE Example -
Table & column names can be double-quoted to use reserved words, e.g.,
"PERCENT"; or to use numbers or special characters in column names, e.g.,"1234"or"key:value". -
TOP <n>returns the first n records (up to 20000 records by default). -
The grouping expression list may contain column names, aliases,
expressions, or positions (e.g.,
GROUP BY 2to aggregate on the 2nd column in theSELECTlist). -
The having expression list may contain grouping expressions or any
grouping expression aliases defined in the
SELECTlist. -
The ordering expression list may contain column names, expressions, or
column positions (e.g.,
ORDER BY 2to aggregate on the 2nd column in theSELECTlist). The default ordering isASC. The default null ordering isNULLS FIRSTwhen using ascending order andNULLS LASTwhen using descending order. The general format for each comma-separated ordering expression in the list is:ORDER BY Expression Syntax -
LIMITapplies paging to the result set, starting at the 0-based offset (if specified) and returning num rows records.
SELECT Example