Sql Select The Only Rows With Only A Certain Values In Them
i have the same problem here :SQL select rows with only a certain value in them but the solution that i have found work only for one value given, i mean that i want it to work for
Solution 1:
You can use conditional aggregation for this:
select col2
from yourtable
groupby col2
havingsum(col3=1) >0andsum(col3=2) >0andsum(col3 notin (1,2)) =0Solution 2:
SELECT col 2 FROM TABLE WHERE (col 3 =1 OR col 3 =2) AND col 2 NOT IN (SELECT col 2 FROM TABLE WHERE (col 3 <>2 AND col 3 <> 1));
Post a Comment for "Sql Select The Only Rows With Only A Certain Values In Them"