How joins work

When you join two or more tables, the columns being compared must have similar values—that is, values using the same or similar datatypes.

There are several types of joins, such as equijoins, natural joins, and outer joins. The most common join, the equijoin, is based on equality. The following join finds the names of authors and publishers located in the same city:

select au_fname, au_lname, pub_name 
from authors, publishers 
where authors.city = publishers.city 
au_fname      au_lname      pub_name 
--------      --------      -------------------- 
Cheryl        Carson        Algodata Infosystems 
Abraham       Bennet        Algodata Infosystems 
 
(2 rows affected) 

Because the query draws on information contained in two separate tables, publishers and authors, you need a join to retrieve the requested information. This statement joins the publishers and authors tables using the city column as the link:

where authors.city = publishers.city