I'm trying to create a SQL query that will not return rows that have the same ID. I would also like to specify a primary row so that, in the event two rows have the same ID, the primary row will be returned. If no primary row is specified I would like to return the first row.
Here is an example of the database I would like to query.
+----+---------+-------+
| id | primary | label |
+----+---------+-------+
| 1 | Y | A |
| 1 | | B |
| 2 | | C |
| 2 | | D |
| 3 | | E |
+----+---------+-------+
Here is an example of the result I am trying to achieve
+----+---------+-------+
| id | primary | label |
+----+---------+-------+
| 1 | Y | A |
| 2 | | C |
| 3 | | E |
+----+---------+-------+
I've been trying to use select distinct but I'm very unsure as to the direction to pursue to solve this problem. Any help is greatly appreciated. Thank you!