Collection Contents Index FORWARD TO statement GET DATA statement [ESQL] pdf/chap9.pdf

Reference Manual
   CHAPTER 9. SQL Statements     

FROM clause


Function 

To specify the database tables or views involved in a SELECT or UPDATE statement.

Syntax 

... FROM table-expression, ...

Parameters 

table-expression:
table-spec
| table-expression join-type table-spec [ ON condition ]
| ( table-expression, ... )

table-spec:
[userid.]table-name [ [AS] correlation-name ]
| select-statement [ AS correlation-name ( column-name, ... ) ]

join-type:
CROSS JOIN
| [ NATURAL | KEY ] JOIN
| [ NATURAL | KEY ] INNER JOIN
| [ NATURAL | KEY ] LEFT OUTER JOIN
| [ NATURAL | KEY ] RIGHT OUTER JOIN

Permissions 

Must be connected to the database.

Side effects 

None.

See also 

SELECT statement

UPDATE statement

Joins: Retrieving Data from Several Tables

Description 

The SELECT and UPDATE statements require a table list, to specify which tables will be used by the statement.

Views    
Although this description refers to tables, it applies to views unless otherwise noted.

The FROM table list creates a result set consisting of all the columns from all the tables specified. Initially, all combinations of rows in the component tables are in the result set, and the number of combinations is usually reduced by join conditions and/or WHERE conditions.

Tables owned by a different user can be qualified by specifying the user ID. Tables owned by groups to which the current user belongs will be found by default without specifying the user ID (see Referring to tables owned by groups).

The correlation name is used to give a temporary name to the table for this SQL statement only. This is useful when referencing columns from a table with a long name. The correlation name is also necessary to distinguish between table instances if you reference the same table more than once in the same query. If no correlation name is specified, the table name is used as the correlation name for the current statement.

If the same correlation name is used twice for the same table in a table expression, that table is treated as if it were listed only once. For example, in:

SELECT *
FROM sales_order
KEY JOIN sales_order_items,
sales_order
KEY JOIN employee

the two instances of the sales_order table are treated as one instance, this is equivalent to:

SELECT *
FROM sales_order_items
KEY JOIN sales_order
KEY JOIN employee

Whereas:

SELECT *
FROM Person HUSBAND, Person WIFE

would be treated as two instances of the Person table, with different correlation names HUSBAND and WIFE.

You can supply SELECT statements instead of table or view names in the FROM clause. This allows you to use groups on groups, or joins with groups, without creating a view. The tables that you create in this way are derived tables.

Standards and compatibility 

Examples 


Collection Contents Index FORWARD TO statement GET DATA statement [ESQL] pdf/chap9.pdf