Given the dataset
+-----------+---------+
| device_id | section |
+-----------+---------+
| 100 | A |
+-----------+---------+
| 101 | B |
+-----------+---------+
| 102 | B |
+-----------+---------+
| 103 | C |
+-----------+---------+
| 104 | D |
+-----------+---------+
| 105 | C |
+-----------+---------+
| 106 | A |
+-----------+---------+
| 107 | C |
+-----------+---------+
What MySQL query will produce one (and only one) row for each section, selected at random.
Expected results (random variation):
+-----------+---------+
| device_id | section |
+-----------+---------+
| 106 | A |
+-----------+---------+
| 101 | B |
+-----------+---------+
| 105 | C |
+-----------+---------+
| 104 | D |
+-----------+---------+
I have tried several variations using GROUP BY
and DISTINCT
but have not had any success.
--edit-- I updated the title to clarify that I am not asking that a single row be returned, but that I get one, and only one device_id
for each distinct section.