SELECT DISTINCT FormatID FROM [YourTable] WHERE AttribID IN (12,15)

SELECT AttribID FROM MyTable WHERE FormatID IN (12,15) GROUP BY AttribID HAVING COUNT(DISTINCT FormatID ) = 2 EXCEPT SELECT AttribID FROM MyTable WHERE FormatID <> 27

SELECT AttribIDFROM dbo.MyTableWHERE FormatID IN (12,15,27) --list ALL values that need tested, included and excludedGROUP BY AttribIDHAVING MAX(CASE WHEN FormatID = 12 THEN 1 ELSE 0 END) = 1 AND --must be found MAX(CASE WHEN FormatID = 15 THEN 1 ELSE 0 END) = 1 AND --must be found MAX(CASE WHEN FormatID = 27 THEN 1 ELSE 0 END) = 0 --must NOT be found