Inner Joins

An inner join, or equijoin, is a join that uses a condition to specify a relationship between tables in which a column in one table is equal to another column in the other table. In the previous lesson, you learned how to do this using the WHERE clause.

The alternative syntax uses the keyword phrase INNER JOIN to specify a table to join to and the keyword ON to specify a conditional clause that indicates the relationship between the tables.

The following example reproduces the query from Lesson 11, “Joining Tables,” to retrieve all the customer contact information:

mysql> SELECT name,
    -> CONCAT(last_name, ', ', first_name) as contact_name
    -> FROM customers
    -> INNER JOIN customer_contacts
    -> ON customers.customer_code =
    ->    customer_contacts.customer_code ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.