Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
Instead of, or along with, a key or natural join, you can specify a join using an explicit join condition. You specify a join condition by inserting an ON clause immediately after the join. The join condition always refers to the join immediately preceding it. The ON clause applies a restriction to the rows in a join, in much the same way that the WHERE clause applies restrictions to the rows of a query.
The ON clause allows you to construct more useful joins than the CROSS JOIN. For example, you can apply the ON clause to a join of the SalesOrders and Employees table to retrieve only those rows for which the SalesRepresentative in the SalesOrders table is the same as the one in the Employees table in every row of the result. Then each row contains information about an order and the sales representative responsible for it.
For example, in the following query, the first ON clause is used to join SalesOrders to Customers. The second ON clause is used to join the table expression (SalesOrders JOIN Customers) to the base table SalesOrderItems.
SELECT * FROM SalesOrders JOIN Customers ON SalesOrders.CustomerID = Customers.ID JOIN SalesOrderItems ON SalesOrderItems.ID = SalesOrders.ID;
Table references in ON clauses
Generated joins and the ON clause
Types of explicit join conditions
WHERE clauses in join conditions
Discuss this page in DocCommentXchange.
|Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1|