December 30, 2015 at 11:17 pm
Hi All,
What is difference between Left Join Vs Right join since if i swap the table position, i get the same result.
Thanks,
Prashant N
December 30, 2015 at 11:58 pm
Left outer join returns all records from left table, at same time, it brings all matching rows from right table for the given predicate and NULL appears in right side when no matching row exists.
Right outer join returns all records from right table, at the same time, it brings all matching rows from left table for the given predicate, and NULL appears in left side when no matching row exists.
there are lot of example, just Google it.
December 31, 2015 at 11:36 am
Maybe this will give you a better perspective on how the different types of joins work.
DECLARE @Table1 TABLE( MyID int);
INSERT INTO @Table1 VALUES(1),(2),(3),(4)
DECLARE @Table2 TABLE( MyID int);
INSERT INTO @Table2 VALUES(4),(5),(6),(7)
SELECT *
FROM @Table1 t1
--INNER
JOIN @Table2 t2 ON t1.MyID = t2.MyID
SELECT *
FROM @Table1 t1
LEFT
JOIN @Table2 t2 ON t1.MyID = t2.MyID
SELECT *
FROM @Table1 t1
RIGHT
JOIN @Table2 t2 ON t1.MyID = t2.MyID
SELECT *
FROM @Table1 t1
FULL
JOIN @Table2 t2 ON t1.MyID = t2.MyID
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply