MySQL Left Join

March 31, 20191 min readUpdated 1/19/2021

 

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.