Skip to content
Related Articles

Related Articles

SQL Left Join

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 09 Nov, 2021

The LEFT JOIN keyword in SQL returns the all matching records(or rows) and the records(or rows) that are present in the left table but not in the right table. That means that, if a certain row is present in the left table but not in the right, the result will include this row but with a NULL value in each column from the right. If a record from the right table is not in the left, it will not be included in the result.


The syntax for a LEFT JOIN is :

SELECT column_name(s) 
FROM tableA 
LEFT JOIN tableB ON tableA.column_name = tableB.column_name;


In this example we will consider two tables Employee containing details of the employees working in the particular department the and department table containing the details of the department

employee table

E1Varun Singhal2730,000D1
E2Amrita Aggarwal2825,000D2
E3Ravi Anand3034,000D1
E4Nitin Saini3454,000[NULL]
E5Muskan Garg3565,000[NULL]

department table 


To perform left- join on  these two tables we will use the following SQL query :

select emp_no ,emp_name , age, salary ,dept_name, location 
from employee 
left join department on employee.dept_no=department.dept_no;

The output that we will get is as follows :-

E1Varun Singhal2730,000ITDelhi
E3Ravi Anand3034,000ITDelh
E2Amrita Singhal2825,000HRHyderabad
E4Nitin Saini3454,000[NULL][NULL]
E5Muskan Garg3565,000[NULL][NULL]

As left join gives the matching rows and the rows that are present in the left table but not in the right table. Here in this example, we see that the employees that does not work in a particular department, i.e, having dept no values as [NULL], contains [NULL] values of dept name and location after the left join.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!