Reputation: 1536
I've tried to search answer here, there are few questions are quite similar with my question but i still can't figure out how to GROUP BY below.
MYSQL Structure:
ID | USERID | FRIENDID
1 | 14 | 65
2 | 65 | 14
3 | 12 | 19
4 | 19 | 12
How to GROUP BY ID 1 & ID 2 and ID 3 & ID 4 with php query?
Result:
1. 14 & 65
2. 12 & 19
Upvotes: 3
Views: 216
Reputation: 263723
SELECT LEAST(USERID, FRIENDID) as x,
GREATEST(USERID, FRIENDID) as y
FROM TableName
GROUP BY x, y
Upvotes: 8