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.
| Author |
Topic |
|
Sschuster
Starting Member
26 Posts |
Posted - 2005-09-12 : 16:41:38
|
| I have three tables..1) Accounts2) Orders3) OrdersProcessedI need to come up with all the Orders records that have a matching Accounts record (based on AccountNumber) but do not have a matching OrdersProcessed record (based on OrderID and AccountNumber) and AccountNumber is like 'B%'. I tried the following query and it's not returning what I expect, it returns all the rows from Orders even though they have a matching record in the OrdersProcessed table. Any ideas?SELECT O.AccountNumber, O.OrderID, O.Quantity, O.BuySellFROM PFX_Orders O FULL OUTER JOIN PFX_OrdersProcessed P ON O.AccountNumber = P.AccountNumberAND O.OrderID = B.OrderID INNER JOIN PFX_Accounts A ON A.AccountNumber = O.AccountNumberWHERE O.AccountNumber like 'B%' |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-09-12 : 17:06:15
|
[code]SELECT O.AccountNumber, O.OrderID, O.Quantity, O.BuySellFrom PFX_Orders O Inner Join PFX_Accounts A On A.AccountNumber = O.AccountNumberLeft JOIN PFX_OrdersProcessed P On O.AccountNumber = P.AccountNumberand O.OrderID = B.OrderID WHERE O.AccountNumber like 'B%'and P.AccountNumber is null[/code]Corey Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now." |
 |
|
|
Sschuster
Starting Member
26 Posts |
Posted - 2005-09-12 : 17:14:24
|
| PERFECT! Exactly what I was looking for. Thanks! |
 |
|
|
|
|
|