Reputation: 105
I want sno where level is 5836 alone, if the sno has multiple levels even if it has 5836, it must be ignored.
sno | levels |
---|---|
1 | 5836 |
1 | 5838 |
2 | 5838 |
2 | 5836 |
3 | 5836 |
4 | 5838 |
5 | 5836 |
Expected Output
sno | levels |
---|---|
3 | 5836 |
5 | 5836 |
This is what I tried, but I think logic isnt working
with T1 as
(
SELECT id, levels
from tablename
)
select id
from T1
where levels = 5836 and levels <> 5838
[dbfiddle] (https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=9cc0b0e8a42fb181754ccca7a40d774b)
Upvotes: 0
Views: 34
Reputation: 1269463
Use aggregation:
select sno
from tablename
group by sno
having min(level) = 5836 and min(level) = max(level);
Upvotes: 1