4.5. SELECT

The SELECT command retrieves data from the database allowing the selection of rows, columns and tables.

4.5.1. SELECT Statement Syntax

The complete SELECT statement syntax is shown below. Following this material the SELECT statement parameters will be described for each clause in turn.

Syntax
SELECT [ DISTINCT | ALL ] [ TOP n [ PERCENT ] [ WITH TIES ] ]   < select_list >
[ INTO new_table ]
[ FROM { < table_source > } [ ,...n ] ]
[ WHERE < search_condition > | < old_outer_join > ]
[ GROUP BY [ ALL ] group_by_expression [ ,...n ] [ WITH {CUBE | ROLLUP } ] ] [ HAVING < search_condition > ] [ ORDER BY {column_name_or_alias [ ASC | DESC ] | column_position [ ASC | DESC ] } [ ,...n] ] [ COMPUTE { { AVG | COUNT | MAX | MIN | STDEV | STDEVP ...

Get Transact-SQL Desk Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.