TurboSQL Guide


Previous  Top  Next

Retrieves data from tables.

SELECT [TOP number] [DISTINCT] * | column_list
FROM table_reference
[WHERE predicates]
[ORDER BY order_list]
[GROUP BY group_list]
[HAVING having_condition]


Use the SELECT statement to

Retrieve a single row, or part of a row, from a table, referred to as a singleton select.
Retrieve multiple rows, or parts of rows, from a table.
Retrieve related rows, or parts of rows, from a join of two or more tables.

The SELECT clause defines the list of items returned by the SELECT statement. The SELECT clause uses a comma-separated list composed of: table columns, literal values, and column or literal values modified by functions. Literal values in the columns list may be passed to the SELECT statement via parameters. You cannot use parameters to represent column names. Use an asterisk to retrieve values from all columns.

Columns in the column list for the SELECT clause may come from more than one table, but can only come from those tables listed in the FROM clause. See Relational Operators for more information on using the SELECT statement to retrieve data from multiple tables. The FROM clause identifies the table(s) from which data is retrieved.

If TOP is specified in the statement, the number of rows in the subset is limited to the given number. Top is evaluated after all other clauses and therefore refers to the sorted or grouped result set in case the order by clause and/or the group by clause are present.

If the DISTINCT keyword is present, duplicate rows in the result table are suppressed. DISTINCT cannot be used together with GROUP BY. If a SELECT statement contains both GROUP BY and DISTINCT, the DISTINCT keyword is ignored.

The following statement retrieves data for two columns in all rows of a table.

SELECT custno, company
FROM orders

See also