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 |
|
omega1983
Starting Member
40 Posts |
Posted - 2009-11-11 : 10:09:36
|
| Here is an output of some data. Note in the first instance I want to eliminate John Smith because of the presence of SECONDARYDEPTID 14. Eliminating Phil Jones is the easy part. Eliminating John Smith is difficult because SQL evaluates each line individually so his entry 14 is eliminated but he still shows up under #15ID NAME DEPT SECONDARYDEPTID1 John Smith ENGINEERING 141 John Smith ENGINEERING 15----------------I want to eliminate both-----------------2 Sam Brown ENGINEERING 153 Louise Brown ENGINEERING 15----------------------I want to eliminate Phil Jones------5 Phil Jones ENGINEERING 14select ID,NAME,DEPT,SECONDARYDEPTfrom myTable whereSECONDARYDEPT not = '14'this query will not eliminate both John Smith's entry 14 and 15. How can I eliminate both in this case |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-11-11 : 10:16:42
|
eliminate once there is a 14 ? select ID, NAME, DEPT, SECONDARYDEPTfrom myTable twhere not exists ( select * from myTable x where x.ID = t.ID and x.SECONDARYDEPT = '14' ) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|