MYSQL - LEFT JOIN Query

 LEFT JOIN Query in mysql is used to join multiple tables which return all the records from the first (left-side) table even no matching records found from the second (right side) table. If it will not find any matches record from the right side table, then returns null.

  • We can use MySQL LEFT JOIN Multiple Tables.
  • We can use LEFT JOIN with WHERE Clause.
  • We can use MySQL LEFT JOIN with Group By Clause.
  • We can use MySQL LEFT JOIN with USING Clause.


MYSQL Syntax :

SELECT field_name1, field_name2, ....
FROM table1
LEFT JOIN table2
ON Join_Condition;

Left Join MYSQL Query
MySQL LEFT JOIN – Venn Diagram


MYSQL Query Example :
SELECT s.stud_id,s.stud_name,m.maths,m.science FROM tblstudent s LEFT JOIN tblmarks m on s.stud_id=m.stud_id

 

Left join Query
stud_id stud_name maths science
1 manish patel 45 78
3 Raju modi 65 76
4 jacky jain NULL NULL

Explain:

  • The tblstudent is the left table and tblmarks is the right table.
  • Above LEFT JOIN clause query returns all records of  table tblstudent even no matching records found from table tblmarks with null value.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

98792