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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Eliminate all records based on one instance

Author  Topic 

omega1983
Starting Member

40 Posts

Posted - 2009-11-06 : 13:57:29
I have a query:

select phnID,phnumber
from phone
where phnRest not in ('1','2','3')

Here is some sample data
phnID phnumber phnRest
1 3239055 5 (shows up)
1 3239055 1 (eliminated)
2 5425501 6

In this example phnID has phnRest 1 and 5. Since phnRest 1 is eliminated, I also want phnRest 5 to be eliminated too.

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-11-06 : 14:09:42
Do you keep log of what's being deleted? If yes, then you can "if exist" to find out which one you need to delete then use Delete to delete unwanted records.
Go to Top of Page

medtech26
Posting Yak Master

169 Posts

Posted - 2009-11-06 : 19:51:35
This might do the trick.

SELECT phnID, phnumber
FROM phone
WHERE phnID in (SELECT phnID FROM phone WHERE phnRest not in ('1','2','3'))
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-07 : 07:26:20
What do mean when you say: "I also want phnRest 5 to be eliminated too."?
Do you mean you want to delete it from table and also delete the record the has phnRest=1?
Do you mean you want to update the record so phnRest changes from 5 to 1?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Pradip
Starting Member

32 Posts

Posted - 2009-11-09 : 03:12:39
please explain question what exactly is the requirement.

pradipjain
Go to Top of Page
   

- Advertisement -