Assume this table,
id name class
---+-----+------
1 a rare
2 a common
3 b common
4 b common
and we group rows by name
. How to select from each group the only rare row if exists or else (if rare does not occur in the grouping) the first common row, so that we get
id name class
---+-----+------
1 a rare
3 b common