The select syntax can be simpler or more complex than shown in the previous example. A simple select statement contains only the select clause; the from clause is almost always included, but is necessary only in select statements that retrieve data from tables. All other clauses, including the where clause, are optional.
The full syntax of the select statement is documented in the Reference Manual: Commands.
TOP unsigned_integer lets you limit the number of rows in a result set; specify the number of rows you want to view. TOP is also used in the delete and update commands, for the same purpose. See the Reference Manual: Commands.
Use the clauses in a select statement in the order shown above. For example, if the statement includes a group by clause and an order by clause, the group by clause must precede the order by clause.
Qualify the names of database objects if there is ambiguity about the object referred to. If several columns in multiple tables are called “name,” you may need to qualify “name” with the database name, owner name, or table name. For example:
select au_lname from pubs2.dbo.authors
Since the examples in this chapter involve single-table queries, column names in syntax models and examples are usually not qualified with the names of the tables, owners, or databases to which they belong. These elements are omitted for readability; it is never wrong to include qualifiers. The remaining sections in this chapter analyze the syntax of the select statement in more detail.
This chapter describes only some of the clauses and keywords included in the syntax of the select command. The following clauses are discussed in other chapters:
group by, having, order by, and compute are described in Chapter 3, “Using Aggregates, Grouping, and Sorting.”
into is described in Chapter 8, “Creating Databases and Tables.”
at isolation is described in Chapter 23, “Transactions: Maintaining Data Consistency and Recovery.”
The holdlock, noholdlock, and shared keywords (which deal with locking in Adaptive Server) and the index clause are described in Chapter 4, “Using Locking Commands,” in the Performance and Tuning Series: Locking and Concurrency Control. For information about the for read only and for update clauses, see the declare cursor command in the Reference Manual: Commands.
The for browse clause is used only in DB-Library applications. See the Open Client DB-Library/C Reference Manual for details. See also “Using browse mode instead of cursors”.