0

I wanna know that what is the difference between these two queries when both produce the same results:

SELECT a.OrderID,
       ProductID,
       a.LastName
FROM   [Order Details],
       (SELECT Employees.EmployeeID,
               OrderID,
               LastName
        FROM   Employees,
               Orders
        WHERE  Employees.EmployeeID = Orders.EmployeeID
               AND LastName = 'Buchanan')a
WHERE  [Order Details].OrderID = a.OrderID 

and

SELECT Orders.OrderID,
       ProductID,
       LastName
FROM   [Order Details],
       Employees,
       Orders
WHERE  Orders.OrderID = [Order Details].OrderID
       AND Orders.EmployeeID = Employees.EmployeeID
       AND LastName = 'Buchanan' 

first one is a nested join query and second one is a single join query but joining the same three tables and producing the same results...

Martin Smith
  • 438,706
  • 87
  • 741
  • 845
Fawad Khalil
  • 357
  • 3
  • 20

1 Answers1

0

Joins will perform better (for almost all cases) but sub queries are easier to understand and write, especially for people who are newer at SQL. For small data sets you will likely not see any difference, but it will become exponential as your set rises.

Join vs. sub-query

Community
  • 1
  • 1