user1760769
user1760769

Reputation: 33

SQL Group By where no row has value

What is the best way to write this query:

SELECT ID FROM table WHERE "no row with the ID has a created date > '1/1/2012'" GROUP BY ID

In summary, I only want to see grouped ID's where every row has a created date > '1/1/2012'

Upvotes: 0

Views: 351

Answers (2)

DCR
DCR

Reputation: 15647

select * from (table where date > '2012-01-01') group by id

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269445

Use a having clause and look at the maximum created date:

SELECT ID
FROM table
GROUP BY ID
HAVING MAX(CreatedDate) <= '2012-01-01'

Upvotes: 2

Related Questions