Previous Topic: Compare Values from Multiple TablesNext Topic: Using Subqueries


Define Aliases or Correlation Values for Table Names

Referencing several tables in a SELECT statement can make that statement long and complex. So, you can define aliases or correlation values for table names, using the AS keyword as shown in the following example:

FROM tablename1 AS alias1, tablename2 AS alias2

You may use a single blank in place of the AS keyword to define an alias or correlation value for a table. For example, the following statement is equivalent to the preceding example:

FROM tablename1 alias1, tablename2 alias2

A comma separates distinct table names, in contrast to a blank without a comma, which separates the original table name from its alias or correlation value.

Once you define an alias or a correlation value for a table name, you can use it in subsequent parts of your SELECT statement. For example, a WHERE clause like the one below might follow the clause defining alias1 and alias2:

WHERE alias2.colname1 = tablename2.colname2
  AND alias1.colname1 = tablename3.colname3