Chapter 9 SQL Statements
601
SELECT statement
Use this statement to retrieve information from the database.
SELECT [ ALL | DISTINCT ] [ FIRST | TOP
n
]
select-list
…[ INTO {
host-variable-list
|
variable-list
} ]
…[ FROM
table-expression
]
…[ WHERE
search-condition
]
…[ GROUP BY
group-by-list
]
…[ HAVING
search-condition
]
…[ ORDER BY {
expression
|
integer
} [ ASC | DESC ], … ]
select-list
:
{
column-name
|
expression
} [ [ AS ]
alias-name
], …| *
group-by-list
:
{
column-name
|
alias-name
|
function
|
expression
}, …
Must have SELECT permission on the named tables and views.
None.
"Expressions" on page 230
"FROM clause" on page 532
"Search conditions" on page 239
"UNION operation" on page 633
"Joins: Retrieving Data from Several Tables" on page 195 of the book ASA
User’s Guide
The SELECT statement is used for retrieving results from the database.
A SELECT statement can be used in Interactive SQL to browse data in the
database, or to export data from the database to an external file.
A SELECT statement can also be used in procedures and triggers or in
embedded SQL. The SELECT statement with an INTO clause is used for
retrieving results from the database when the SELECT statement only
returns one row. For multiple row queries, you must use cursors.
A SELECT statement can also be used to return a result set from a
procedure.
ALL or DISTINCT All (the default) returns all rows that satisfy the clauses
of the SELECT statement. If DISTINCT is specified, duplicate output rows
are eliminated. Many statements take significantly longer to execute when
DISTINCT is specified, so you should reserve DISTINCT for cases where it
is necessary.
FIRST or TOP These keywords are principally for use with ORDER BY
queries. You can explicitly retrieve only the first row of a query or the first n
rows of a query.
Function
Syntax
Permissions
Side effects
See also
Description
Parameters