Mysql Select reciprocal pairs of records, without duplicates
mysql, select
Solution
You could use MySQL's `LEAST()` and `GREATEST()` functions, together with `DISTINCT`:
SELECT DISTINCT LEAST(a, b), GREATEST(a, b) FROM mytable
Problem
I have a table with two columns: - person_id - person_id with whom 1st field id is in cooperation I need to select all cooperation pairs, it is easy but in what is the problem: table have data like: `987` - `102`, `103 - 104`, `104 - 103`, `21 - 102`. As the result with such data i should have 3 cooperation pairs `987 - 102`, `103-104`, `21-102`, as you see `103 - 104` and `104 - 103` records have the same logic, how can I avoid duplicating of them. Any idea? Thanks, and best regards. Anton.