How to exclude the entire result of a Grouped row based on a value of any of the rows it contains I have a table that looks something like this:
 ID | Class | Item
 ---+-------+------
 1  | 1     | 1
 2  | 1     | 2
 3  | 2     | 1
 4  | 2     | 3
 5  | 3     | 2

and a query that looks something like this:
Select Class, MAX(Item) FROM myTable WHERE Item &lt;&gt; 3 GROUP BY Class

This results in:
  Class | Item
 -------+------
  1     | 2
  2     | 1
  3     | 2

However I want to exclude all results where a Class contains an Item with the value of 3, not just rows that are 3 so it should return:
  Class | Item
 -------+------
  1     | 2
  3     | 2
You can use something like this:
Select Class, MAX(Item) 
FROM myTable 
WHERE class not in (
         select class from #demo where item  = 3
                    ) 
GROUP BY Class