What are queries?  Choosing columns using the select clause

Chapter 2: Queries: Selecting Data from a Table

select syntax

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.

TOP unsigned_integer is an option designed to limit the number of rows in a result set, by allowing you to specify the number of rows you want to see. For information and examples of this feature, see Vol.2, Commands, in the Reference Manual. TOP is also used in the delete and update commands, for the same purpose.

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 have 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:

The holdlock, noholdlock, and shared keywords (which deal with locking in Adaptive Server) and the index clause are described in the Performance and Tuning Guide. For information about the for read only and for update clauses, see the declare cursor command in the Reference Manual.

NoteThe 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”.





Copyright © 2005. Sybase Inc. All rights reserved. Choosing columns using the select clause

View this book as PDF