-1

I have two tables 1.Employees 2.Orders. I execute Left Join and Right Join queries differently when I change positions of table name then I got same output so why we use Left Join & Right Join differently?

Right Join Query

SELECT Orders.OrderID,Employees.EmployeeID, Employees.LastName, 
Employees.FirstName
FROM Employees
Right JOIN Orders 
ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;

Left Join Query

SELECT Orders.OrderID, Employees.EmployeeID, Employees.LastName, 
Employees.FirstName
FROM Orders
Left JOIN Employees 
ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;

Output of both queries will same

  • 1
    There is no difference. It's merely syntax. You generally don't see many Right Joins out in the wild (except in machine produced code like Business Objects which LOVES its Right Joins). – JNevill Jul 18 '19 at 13:05
  • 2
    Possible duplicate of [What is the difference between Left, Right, Outer and Inner Joins?](https://stackoverflow.com/questions/448023/what-is-the-difference-between-left-right-outer-and-inner-joins) – Madhur Bhaiya Jul 18 '19 at 13:07
  • 1
    To get the same result between Left and Right Join query, you need to change both the table order and the join type. But you get different result if you change only one of them. So basically you use left vs right join based on how you want the query result look like. – Chetan Jul 18 '19 at 13:08
  • IANAL so I can't tell if I can copy content from Quora, but see the section "But why do both flavors exist?" at [Database Systems: What are the differences between a left join and a right join?](https://www.quora.com/Database-Systems-What-are-the-differences-between-a-left-join-and-a-right-join) which gives one reason. – Andrew Morton Jul 18 '19 at 13:19
  • I got solution If we want to join third table then we have to write left join and right join to get particular output. Then output will be different. – Nikhil Jojare Oct 14 '19 at 11:02

1 Answers1

0

It is the same, since you change positions of the tables. Most people prefer the left join, because you can easily read the 'from tableA' as tableA being (visually) the 'primary' table. Since that's the one that shows all its results in the left join (even if there's no data about certain records in the other table).

Neli
  • 93
  • 9