selecting when an aggregate column has two or more items

Posted by blockhead on Stack Overflow See other posts from Stack Overflow or by blockhead
Published on 2010-05-06T17:25:05Z Indexed on 2010/05/06 17:28 UTC
Read the original article Hit count: 272

Filed under:
|

Let's say I had a query like this:

SELECT * FROM (
  SELECT 'a' AS a, '1' AS b
UNION 
  SELECT 'a' AS a, '2' AS b
UNION
  SELECT 'b' AS a, '1' AS b) AS a 
GROUP BY a.a 

In this case "a".b is an aggregate of 1,2 while "b".b is only an aggregate of 1.

How can I select only "a"?

© Stack Overflow or respective owner

Related posts about sql

Related posts about group-by