I'm trying to write a query that would select only the rows that have events which where the only events in that year.
Eg:
Year Event
2011 A
2011 B
2012 C
2013 B
2013 D
2014 D
So, I would like to get the rows 2012 C
and 2014 D
in the results.
I tried doing a GROUP BY
on Year
, but that wouldn't let me select the Event
column.
2011 and 2013 have 2 events, so these shouldn't be in the results.
Please help.
EDIT: I could write a nested query to get the only the rows having count(Year) = 1
with GROUP BY Year
, but I'm unable to get the Event
column selected in the outer query
SELECT Year, Event from table where Year in (SELECT Year from table GROUP BY Year Having count(*) = 1) as count;