Combine Data from Various Tables
Learn how to combine multiple tables using join.
We'll cover the following...
Join or inner join
In this lesson, we’ll write a select
statement that will display the combined information from all the tables. So, we’ll see the customers in one result set with their corresponding orders, order details, and products. The select
command used to achieve that result isn’t complex. The select
query is only long because we want to combine the information from many tables. Combining information from two tables is done with the join
technique, which relies on the foreign keys between the tables.
Joining customers
with orders
If we want to combine the information between customers
and orders
, we start with the following:
select * from customers join orders;
This tells MySQL that we want to combine the information from the customers
table with the information from the orders
table. Giving only the table names isn’t enough for join
. We need to tell MySQL which columns we want to use the on
clause.
Note ...