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 |
donar
Starting Member
22 Posts |
Posted - 2005-06-15 : 12:39:48
|
Hi, guysI have a table with 4 fields: ISN, type, sequence, property. The ISN, type, sequence together is the primary key. Now I am trying to find out ISNs with no purticular type. create table #temp(isn int,type varchar(20),sequence int,property varchar(65))insert into #temp select 9,'AGE',1,'Ordovician' union allselect 9,'AGE',2,'Cambrian' union allselect 9,'AREA',1,'Nova Scotia, southern' union allselect 9,'KEYWORD',1,'veins, stratabound' union allselect 97,'KEYWORD',1,'veins' union allselect 108,'KEYWORD',2,'veins, fissure'I would like to find out which ISNs does not have type='AGE', how can I do it?The sequenc in the table does not have real meaning, just use it to make the first three fields as a key. sequence could be not sequencial.Thanks! |
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2005-06-15 : 13:18:11
|
Is this what you want?SELECT DISTINCT isn FROM #temp WHERE type <> 'AGE' |
|
|
KLang23
Posting Yak Master
115 Posts |
Posted - 2005-06-15 : 13:43:58
|
I think this should do it:Select Distinct isn from #Temp T1 Where type <> 'AGE' and Not Exists (Select * From #Temp T2 Where T1.isn = T2.isn and T2.type = 'AGE') This will return all isn's that have a row that isn't type "AGE" that don't have a row that is type "AGE"Returns:isn ----------- 97108[/code]Cheers |
|
|
|
|
|
|
|