Skip to main content
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 EXCLUDE function 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 the ssn & date_of_birth columns:
    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 2 to aggregate on the 2nd column in the SELECT list).
  • The having expression list may contain grouping expressions or any grouping expression aliases defined in the SELECT list.
  • The ordering expression list may contain column names, expressions, or column positions (e.g., ORDER BY 2 to aggregate on the 2nd column in the SELECT list). The default ordering is ASC. The default null ordering is NULLS FIRST when using ascending order and NULLS LAST when using descending order. The general format for each comma-separated ordering expression in the list is:
    ORDER BY Expression Syntax
  • LIMIT applies paging to the result set, starting at the 0-based offset (if specified) and returning num rows records.
SELECT Example