'How to convert SQL subquery into Join Clause?
Good day everyone,
I have been attempting to convert the following SQL statement into a join clause, however I have been unable to figure out how to do it and was wondering if I could get some help.
Here is the statement:
SELECT OrderID FROM Orders
WHERE OrderDate = (SELECT orderDate FROM Orders WHERE OrderID = 10280);
I am essentially trying to get all orderIDs that were placed on the same date as the Order with OrderID 10280.
Thanks,
Solution 1:[1]
Try this:
SELECT o.OrderId
FROM Orders o
JOIN Orders ord
ON o.OrderDate = ord.OrderDate
WHERE ord.OrderID = 10280;
You can have a better understanding from here: https://www.sqlservertutorial.net/sql-server-basics/sql-server-self-join/#:~:text=A%20self%20join%20allows%20you,join%20or%20left%20join%20clause.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Naveen Kumar |
