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
 General SQL Server Forums
 New to SQL Server Programming
 filter out

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-09-10 : 23:38:13

status id
new 123
old 123
pending 123
new 456
old 456

i would like to take out all account which doesn't have the status='pending'. I have lots of ID to filter.
But it seems to be still in my output.

select * from tableA
where status <> 'pending'

i get this output:

status id
new 123
old 123
new 456
old 456

i want my output to be like this:
status id
new 456
old 456

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-09-10 : 23:50:05
[code]select *
from tableA a
where NOT EXISTS
(
SELECT *
FROM tableA x
WHERE x.id = a.id
AND x.status = 'pending'
)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-09-11 : 00:06:02
thanks..
is working fine now!
Go to Top of Page
   

- Advertisement -