select

Description

Retrieves rows from database objects. You can issue this command either as language command or a CT-Library cursor request.

Syntax

select select_list [from [[database.]owner.]{table_name |view_name}
[,[[database.]owner.]{table_name|view_name}]...] [where search_conditions] 

Parameters

select_list

is one or more of the following items:

  • A list of column names in the order in which you want them returned

  • An aggregate function

  • Any combination of the items listed previously

from

indicates the particular tables and views to use in the select statement.

table_name, view_name

lists tables and views used in the select statement. If more than one table or view is in the list, their names are separated by commas. Table names and view names are given correlating names. This is done by providing the table or view name, then a space, then the correlation name, such as:

	select * 
 		from publishers t1, authors t2
search_conditions

sets the conditions for the rows that are retrieved. A search condition can include column names, constants, joins, the keywords is null, is not null, or, like, and, or any combination of these items.

group by

finds a value for each group. These values appear as new columns in the results, rather than as new rows.

order by

sorts the results by columns.

having

sets conditions for the group by clause, similar to the way that where sets conditions for the select clause. There is no limit on the number of conditions that can be included.

union

returns a single result set that combines the results of two or more queries. Duplicate rows are eliminated from the result set unless the all keyword is specified.

read only

indicates that the cursor is a read-only cursor, and that updates cannot be applied to rows made current by it.

update

indicates that the cursor is an updatable cursor, and that the rows it makes current can be deleted or updated.

Examples

Example 1

select count(*) from publishers for read only

Example 2

select pub_id, pub_name, city, state from publishers for read only

Example 3

select pub_name, pub_id
 from publishers 

Example 4

select type, price from titles 
 where price > @p1 for update of price

Example 5

select stor_id, stor_name from sales union
 select stor_id, stor_name from sales_east

Usage