MySQL Left Join

 

The LEFT JOIN clause is used to join two or more tables together. The main table will return all of its rows and the matching rows from the joining tables. If the joining tables don’t have the matching rows then MySQL will use NULL to represent those rows.

SELECT 
    t1.c1, t1.c2, t2.c1, t2.c2
FROM
    main_table_name t1
LEFT JOIN
    table2 t2 ON t1.c1 = t2.c1;

Basically, you are getting everything from the main table and the matching rows from the joining tables.

Note that if LEFT JOIN is used with WHERE or/and HAVING then all rows must satisfy all conditions.

 

 




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 *