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 |
|
RowsAndColumns
Starting Member
6 Posts |
Posted - 2010-05-23 : 22:33:23
|
| This should be simple, but I'm just drawing a blank on how to do it!Let's say I have a table called Orders_tbl, and another called Orders_Amount_tbl. I want to list the Order_Numbers from Orders_tbl, that DO NOT appear in Order_Amount_tbl. BUT, only when Currency = XX.This means that the Order_Number may appear in Order_Amount_tbl several times, each time with a different currency. Let's see if I can draw this out:Orders_Amount_tbl________________Orders_tbl Order_Number---------------------------> Order_NumberCurrencyEg. Order_Number = 1234 is in Orders_tbl. I know this should be simple!!Thanx!! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-05-23 : 22:38:44
|
use LEFT JOIN or NOT EXISTSSELECT *FROM Orders_tbl o LEFT JOIN Orders_Amount_tbl a ON o.Order_Number = a.Order_Number AND a.Currency = 'XX'WHERE a.Order_Number IS NULL KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
RowsAndColumns
Starting Member
6 Posts |
Posted - 2010-05-24 : 01:20:37
|
Your reply is not displaying properly.Is 'AND a.Currency = 'XX'' part of LEFT JOIN section, or part of the WHERE clause?Thanks!quote: Originally posted by khtan use LEFT JOIN or NOT EXISTSSELECT *FROM Orders_tbl o LEFT JOIN Orders_Amount_tbl a ON o.Order_Number = a.Order_Number AND a.Currency = 'XX'WHERE a.Order_Number IS NULL KH[spoiler]Time is always against us[/spoiler]
Thanx!! |
 |
|
|
|
|
|