Retrieves rows from database objects.
Transact-SQL Syntax
select [all | distinct] select_list [into [[database.]owner.]table_name] [from [[database.]owner.]{view_name | table_name [(index index_name [prefetch size][lru | mru])]} [holdlock | noholdlock] [shared] [,[[database.]owner.]{view_name | table_name [(index index_name [prefetch size][lru | mru])]} [holdlock | noholdlock] [shared]]...]
[where search_conditions]
[group by [all]aggregate_free_expression [, aggregate_free_expression]...] [having search_conditions]
[order by {[[[database.]owner.]{table_name. | view_name.}] column_name | select_list_number | expression} [asc | desc] [,{[[[database.]owner.]{table_name. | view_name.}] column_name | select_list_number | expression} [asc | desc]]...]
[compute row_aggregate(column_name) [, row_aggregate(column_name)]... [by column_name [, column_name]...]]
[for {{read only | update [of column_name_list]}]
[at isolation {read uncommitted | read committed | serializable}]
[for browse]
ODBC Syntax
SELECT [ALL|DISTINCT]select_list
FROM table_reference_list
[WHERE search_condition]
[GROUP BY column_name[,column_name]...]
[HAVING search_condition]
[UNION [ALL]select_statement]... [order_by_clause]
SELECT [ALL|DISTINCT]select_list
FROM table_reference_list
[WHERE search_condition]
FOR UPDATE OF [column_name[,column_name]...]
select * from publishers t1, authors t2
select count(*) from publishers for read only
select pub_id, pub_name, city, state from publishers for read only
select type, price from titles where price > @p1 for update of price
select stor_id, stor_name from sales union select stor_id, stor_name from sales_east
You can issue this command as a language command or a client-based cursor request.
This statement is accepted and sent to ODBC without change, subject to the qualifications listed in this section.
The TEXTPTR() function cannot appear in the select list.
If a cursor is passed a new set of parameters before it is opened, it can be reused multiple times.
The data values used in the where clause search conditions are passed as cursor parameters, using the datatype associated with the column.
Cursor parameters are indicated with the “@” character when Transact-SQL syntax is used, and with a question mark when passthrough mode is used.
The availability of the GROUP BY, HAVING, and UNION clauses depends upon the ODBC driver level of conformance.