Eliminating duplicate query results with distinct  Selecting rows using the where clause

Chapter 2: Queries: Selecting Data from a Table

Specifying tables with the from clause

The from clause is required in every select statement involving data from tables or views. Use it to list all the tables and views containing columns included in the select list and in the where clause. If the from clause includes more than one table or view, separate them with commas.

At most, a query can reference 50 tables and 46 worktables (such as those created by aggregate functions). The 50-table limit includes:

The from syntax looks like this:

select select_list 
     [from [[database.]owner.] {table_name |view_name}
                [holdlock | noholdlock] [shared]
         [, [[database.]owner.] {table_name | view_name}
                  [holdlock | noholdlock] [shared]]...] 

Table names can be between 1 and 255 bytes long. You can use a letter, @, #, or _ as the first character. The characters that follow can be digits, letters, or @, #, $, _, ¥, or £. Temporary table names must begin either with “#” (pound sign), if they are created outside tempdb, or with “tempdb..”. Temporary table names cannot be greater than 238 bytes, as Adaptive Server adds an internal numeric suffix of 17 bytes to ensure that the name is unique. For more information, see Chapter 8, “Creating Databases and Tables.”

The full naming syntax for tables and views is always permitted in the from clause:

database.owner.table_name 
     database.owner.view_name 

However, the full naming syntax is necessary only if there is some confusion about the name.

You can give table names correlation names to save typing. Assign the correlation name in the from clause by giving the correlation name after the table name, like this:

select p.pub_id, p.pub_name 
from publishers p 

All other references to that table (for example, in a where clause) must also use the correlation name. Correlation names cannot begin with a numeral.





Copyright © 2005. Sybase Inc. All rights reserved. Selecting rows using the where clause

View this book as PDF