LEFT JOIN (also called LEFT OUTER JOIN) is used to retrieve all records from the left table and the matched records from the right table.
If there is no match found in the right table, the result will still include the left table’s row, and the right table’s columns will show NULL
.
SELECT table1.column_name, table2.column_name FROM table1 LEFT JOIN table2 ON table1.common_column = table2.common_column;
Suppose you have two tables — students and fees. You want to show all students, even if they haven’t paid any fees.
SELECT students.student_name, fees.total_fees FROM students LEFT JOIN fees ON students.student_id = fees.student_id;
SELECT students.student_id, students.student_name, students.student_course, fees.total_fees, fees.paid_fees, fees.pending_fees, fees.status FROM students LEFT JOIN fees ON students.student_id = fees.student_id;