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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-03-07 : 07:44:14
|
| Kunaal writes "I have a master table ministry_master with column ministry_id and a ministry_locale table that has cols ministry_id(foreign key relationship with Ministry_master.Ministry_id) and culture_id. Now for every Ministry_id, value, the locale will have culture_id value 1 and 2 such that a typical table will look likeMinistry_id Culture_Id 1 11 22 12 23 13 34 25 26 2I need to pick rows with culture_id = 2 for which, culture_id = 1 Row doesnt exist. Could you tell me the sql for this?In this example, the result set would be456thanks and regards" |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-03-07 : 08:34:53
|
| SELECT ministry_id from ministry_locale minl1 LEFT OUTER JOIN ministry_locale minl2 on minl1.Ministry_id = minl2.Ministry_id and minl2.culture_id = 1WHERE minl1.culture_id = 2 and minl2.ministry_id is nullEDIT : No that wont work, sorry.-------Moo. :) |
 |
|
|
Chester
Starting Member
27 Posts |
Posted - 2005-03-07 : 08:43:56
|
| select Ministry_idFROM ministry_master where Ministry_id not in (select Ministry_id from test where Culture_Id = '1')and Culture_Id = '2' |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-03-07 : 09:04:30
|
mr mist, why won't that work? This looks like the same thing and it works. Anyway Kunaal, looks like you've got some options.Select distinct a.ministry_idFrom @ministry_locale aLeft JOIN @ministry_locale b ON a.ministry_id = b.ministry_id and b.culture_id = 1where a.culture_id = 2AND b.culture_id is NULL Be One with the OptimizerTG |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-03-07 : 09:44:32
|
| Yeah I was missing the distinct.-------Moo. :) |
 |
|
|
|
|
|