- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is MySQL LEFT JOIN and how can we write MySQL query for it?
While joining two tables using a LEFT join, the concept of left table and right table are introduced and a join-predicate is also required. It returns all the rows in the left table including rows that satisfy join-predicate and also rows which do not satisfy join-predicate.
For the rows that do not match the join-predicate, NULL appears in the column of the right table in the result set. To understand it, we are taking the example of two tables named tbl_1 and tbl_2 which are having following data −
mysql> Select * from tbl_1; +----+--------+ | Id | Name | +----+--------+ | 1 | Gaurav | | 2 | Rahul | | 3 | Raman | | 4 | Aarav | +----+--------+ 4 rows in set (0.00 sec) mysql> Select * from tbl_2; +----+---------+ | Id | Name | +----+---------+ | A | Aarav | | B | Mohan | | C | Jai | | D | Harshit | +----+---------+ 4 rows in set (0.00 sec)
Now, the query for LEFT JOIN can be as follows −
mysql> SELECT tbl_1.id,tbl_2.id FROM tbl_1 LEFT JOIN tbl_2 ON tbl_1.name = tbl_2.name; +----+------+ | id | id | +----+------+ | 1 | NULL | | 2 | NULL | | 3 | NULL | | 4 | A | +----+------+ 4 rows in set (0.02 sec)
- Related Articles
- What is MySQL RIGHT JOIN and how can we write MySQL query for it?
- How can we write MySQL query for inner joins with the help of keyword JOIN?
- How can we write MySQL query for cross joins with the help of keyword JOIN?
- How MySQL LEFT JOIN can be used to simulate the MySQL MINUS query?
- How can we create a MySQL view with LEFT JOIN?
- How can we distinguish between MySQL CROSS JOIN and INNER JOIN?
- How can we subtract values in MySQL table with the help of LEFT JOIN?
- What MySQL returns if I do not use the keyword ‘RIGHT’ or ‘LEFT’ while writing the query for RIGHT JOIN or LEFT JOIN?
- How can we write MySQL query for inner joins with the help of Comma operator?
- How can we write MySQL query for cross joins with the help of Comma operator?
- How can we check for NULL in a MySQL query?
- How can we convert subqueries to LEFT JOIN?
- How can we create a MySQL view with INNER JOIN?
- How can we create a MySQL view with RIGHT JOIN?
- How can we simulate the MySQL INTERSECT query?

Advertisements