I’m trying to get data where order doesn’t matter with unique ids. So simply my query would be
SELECT DISTINCT id1, id2 FROM messages ORDER BY date
If i have a database with the following data:
id1 | id2 | date
5 | 6 | 1/2/2011
6 | 5 | 1/1/2011
I would only need to load the column with the newest date because the ids are the same 2 people. Really i have to load ids where one of the ids is yours so my real query right now is
SELECT DISTINCT userid_1, userid_2
FROM messages
WHERE userid_2=$dbid
OR userid_1=$dbid
ORDER BY date
and i get a result as [6 5] [5 9] [9 5] [5 15] [5 6] [5 17]
Results 2 and 3 are the same and 1 and 5 are the same. Really only 4 results should be queried. Thanks!
One option is:
DISTINCTwill regard it as same.