| one | two |
-------------
| A | 1 |
| A | 2 |
| B | 1 |
| B | 3 |
| C | 1 |
| C | 4 |
I would like to get no repeats in any column in a query, so the standard
SELECT DISTINCT one,two FROM table;
or SELECT * FROM table GROUP BY one,two;
doesn't quite work, because it looks for distinct in all rows, which in this case would return all 6 rows.
Ideally, I am looking for:
| one | two |
-------------
| A | 1 |
| B | 3 |
| C | 4 |
In PHP (etc.), I would just do this with an array for each column, and if any column has been used before then skip the row. I am not sure how to implement that in MySQL, though.
SELECT * FROM (SELECT * FROM table GROUP BY one) GROUP BY two
- almost works. but because the outer query doesn't see all the alternatives, it will miss valid options, i.e. the inner will collapse to A,B,C but could well pick all 1s for column two, which would mean the second GROUP BY would then collapse it own to 1 row!
I know the order of duplication checking will have an effect on the exact rows returned -- not worried about that -- I just want a good cross section of rows with minimal similar rows.