Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server : do not Select all if true

I have these columns

Id  Status
----------
 1  pass
 1  fail
 2  pass
 3  pass

How do I select all that only have a status of pass but if the Id has at least one fail it will not be selected as well.

like image 892
user3770093 Avatar asked Sep 17 '26 11:09

user3770093


1 Answers

If same id can have multiple passes

SELECT id
from table 
WHERE status = 'pass' 
and id NOT IN (SELECT id FROM table WHERE status = 'fail')
like image 129
Evus Avatar answered Sep 20 '26 00:09

Evus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!