|
<< Click to Display Table of Contents >> Table correlation names |
![]() ![]()
|
Table correlation names are used to explicitly associate a column with the table from which it comes. This is especially useful when multiple columns of the same name appear in the same query, typically in multi-table queries. A table correlation name is defined by following the table reference in the FROM clause of a SELECT query with a unique identifier. This identifier, or table correlation name, can then be used to prefix a column name.
If the table name is not a quoted string, the table name is the default implicit correlation name. An explicit correlation name the same as the table name need not be specified in the FROM clause and the table name can prefix column names in other parts of the statement.
SELECT *
FROM Customer
LEFT OUTER JOIN Orders
ON (Customer.CustNo = Orders.CustNo)
If the table name is a quoted string, you need to do one of the following:
Prefix column names with the exact quoted string used for the table in the FROM clause.
SELECT *
FROM "Customer.db"
LEFT OUTER JOIN "Orders.db"
ON ("Customer.db".CustNo = "Orders.db".CustNo)
Use the full table name as a correlation name in the FROM clause (and prefix all column references with the same correlation name).
SELECT *
FROM "Customer.db" CUSTOMER
LEFT OUTER JOIN "Orders.db" ORDERS
ON (CUSTOMER.CustNo = ORDERS.CustNo)
Use a distinctive token as a correlation name in the FROM clause (and prefix all column references with the same correlation name).
SELECT *
FROM "Customer.db" C
LEFT OUTER JOIN "Orders.db" O
ON (C.CustNo = O.CustNo)