Tuesday, January 30, 2024

Left Join

 What is Left Join?

The SQL left join performs an inner join first with the matching values from the right table and it returns all the values from the left table even if there is no matching join value, it will return a corresponding NULL based on a matching row.















Example
























Table_1

create table Table_1 (A varchar);

Insert into Table_1 (A)

values ('x'),('x'),('x'),('0'),('0'),('z');

 

select * from Table_1;



Table_2

create table Table_2 (A varchar);

Insert into Table_2 (A)

values ('y'),('y'),('0'),('x'),('x');

 

select * from Table_2;



Syntax for Left Join

SELECT table1.column1, table1.column2, table2.column1,....

FROM table1

LEFT JOIN table2

ON table1.matching_column = table2.matching_column;


--left join query--

select *from Table_1 T1

left join Table_2 T2

on T1.A=T2.A;


No comments:

Post a Comment