MySQL Join

 

The INNER JOIN is used to query join multiple tables together. The join condition must match column values from both tables.

SELECT column_name1,column_name2,...
FROM table_name1
INNER JOIN table_name2 ON join_condition1
INNER JOIN table_name3 ON join_condition2;

Basically you are getting what both tables have in common.

Here we are joining the customer table and the address table to show the customer address details.

For each row in the customer table, the INNER JOIN checks if the address_id exists in the column id of the address table. If it does then rows from both table are retrieved and show the columns you specify in the SELECT clause.

Now we are going use INNER JOIN to join 5 tables to show what customers have ordered. Note that for best performance you must limit the number of tables to join. The more tables you join the slower the query tends to perform.

INNER JOIN with a complex join condition

Here we add another condition where zipcode >= 78704.

 




Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!

required
required


Leave a Reply

Your email address will not be published. Required fields are marked *