Accessing and Changing Relational Data

Using Joins

Join conditions can be specified in either the FROM or WHERE clauses; specifying them in the FROM clause is recommended. WHERE and HAVING clauses can also contain search conditions to further filter the rows selected by the join conditions.

Joins can be categorized as:

For example, here is an inner join retrieving the authors who live in the same city and state as a publisher:

USE pubs
SELECT a.au_fname, a.au_lname, p.pub_name
FROM authors AS a INNER JOIN publishers AS p
   ON a.city = p.city
   AND a.state = p.state
ORDER BY a.au_lname ASC, a.au_fname ASC

The tables or views in the FROM clause can be specified in any order with an inner join or full outer join; however, the order of tables or views specified when using either a left or right outer join is important. For more information about table ordering with left or right outer joins, see Using Outer Joins.

See Also

Operators

CAST and CONVERT

Using Operators in Expressions

SELECT