The from clause  Join operators

Chapter 4: Joins: Retrieving Data from Several Tables

The where clause

Use the where clause to determine which rows are included in the results. where specifies the connection between the tables and views named in the from clause. Qualify column names if there is ambiguity about the table or view to which they belong. For example:

where authors.city = publishers.city 

This where clause gives the names of the columns to be joined, qualified by table names if necessary, and the join operator—often equality, sometimes “greater than” or “less than.” For details of where clause syntax, see Chapter 2, “Queries: Selecting Data from a Table.”

NoteYou will get unexpected results if you omit the where clause of a join. Without a where clause, any of the join queries discussed so far produces 69 rows instead of 2. “How joins are processed” explains this result.

The where clause of a join statement can include conditionother than the one that links columns from different tables. In other words, you can include a join operation and a select operation in the same SQL statement. See “How joins are processed” for an example.





Copyright © 2005. Sybase Inc. All rights reserved. Join operators

View this book as PDF