Having the table with 3 columns:
ID category flag
1 A 1
2 A 0
3 A 0
4 B 0
5 C 0
I want to select all rows that have flag = 1
at least once per category.
Expected results:
ID category flag
1 A 1
2 A 0
3 A 0
It can be solved using a temporary table like this:
select ID into #tempTable from someTable where flag = 1
select * from someTable join #tempTable on someTable.ID = #tempTable.ID
But I'd prefer a solution with grouping, which I struggle to came up with. Any help will be appreciated.