Contents Index Eliminating duplicate query results The WHERE clause: specifying rows

ASA SQL User's Guide
  Queries: Selecting Data from a Table

The FROM clause: specifying tables


The FROM clause is required in every SELECT statement involving data from tables, views, or stored procedures.

The FROM clause can include JOIN conditions linking two or more tables, and can include joins to other queries (derived tables). For information on these features, see Joins: Retrieving Data from Several Tables.

Qualifying table names 

In the FROM clause, the full naming syntax for tables and views is always permitted, such as:

SELECT select-list
FROM owner.table_name

Qualifying table, view, and procedure names is necessary only when the object is owned by a user ID that is not the same as the user ID of the current connection, or is not the name of a group to which the user iD Of the current connection belongs.

Using correlation names 

You can give a table name a correlation name to save typing. You assign the correlation name in the FROM clause by typing it after the table name, like this:

SELECT d.dept_id, d.dept_name
FROM Department d

All other references to the Department table, for example in a WHERE clause, must use the correlation name. Correlation names must conform to the rules for valid identifiers.

For more information about the FROM clause, see FROM clause.

Querying from objects other than tables 

The most common elements in a FROM clause are table names. It is also possible to query rows from other database objects that have a table-like structure—that is, a well-defined set of rows and columns. In addition to querying from tables and views, you can use derived tables (which are SELECT statements) or stored procedures that return result sets.

For example, the following query operates on the result set of a stored procedure.

SELECT *
FROM sp_customer_products( 149 )

For more information, see FROM clause.


Contents Index Eliminating duplicate query results The WHERE clause: specifying rows