Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Search for all missing order & order details

Author  Topic 

fawadafr
Starting Member

47 Posts

Posted - 2010-04-06 : 13:26:20
Hello,
I would like to write a SQL statement to search for all the orders that do not have corresponding order details and vice-versa. I wrote the following small statement but does not return any value, in fact it generate error:


SELECT OrderDetailID
,OrderID
FROM OrderDetails
WHERE OrderID.OrderDetails <> OrderID.Orders


Could you please provide me with some instructions?

Thank you,


--
Fawad Rashidi

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-06 : 13:31:41
[code]SELECT o.*
FROM Order o
LEFT JOIN OrderDetails od
ON od.OrderID = o.OrderID
WHERE od.OrderID IS NULL

SELECT od.*
FROM OrderDetails od
LEFT JOIN Order o
ON od.OrderID = o.OrderID
WHERE o.OrderID IS NULL
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

fawadafr
Starting Member

47 Posts

Posted - 2010-04-07 : 13:53:05
Thank you very much!

--
Fawad Rashidi
Web Developer
www.fawadafr.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-07 : 13:54:14
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -