Correlation Names

From InterBase
Jump to: navigation, search

Go Up to InterBase Quick Start: Part IV - Retrieving Data

Once you begin to query multiple tables, it becomes important to identify unambiguously what table each column is in. The standard syntax for doing this is to state the table name followed by a period and the column name:

 table_name.col_name

In complex queries, this can get very tedious, so InterBase permits you to state a shorter version of the table name in the FROM clause of a join. This short name is called a correlation name or an alias. You will see many examples of correlation names in the next few pages. The form is as follows:

 SELECT a.col, b.col FROM table_1 a, table_2 b 
     ON a.some_col = b.some_col
     WHERE a.conditional_col <condition>
     ...

Notice the FROM clause, where table_1 is given the correlation name of a and table_2 is named b. These abbreviated names are used even in the initial select list.

Important: If you include a subquery in a join, you must assign new correlation names to any tables that appeared in the main query.

Advance To: