SirChick Posted January 2, 2008 Share Posted January 2, 2008 I have a query which loads up a list in order of two groups... this is sort what it does: Say you have a list of reports in a database.. each report has chat logs and these are on a different table. Now what im trying to do is order them firstly so that the users that are not staff are the priority in the list and then the staff, and then that is ordered by time ASC like so: User - 3 days ago User - 2 days ago User - 2 minutes ago Staff - 10 days ago Staff - 7 days ago You see what i mean ? $GetAppeals = mysql_query("(SELECT * FROM `reportsituation` a LEFT JOIN `staff` b ON a.SaidBy != b.UserID ORDER BY a.SaidBy, a.Saidtime) UNION ALL (SELECT * FROM `reportsituation` c LEFT JOIN `staff` d ON c.SaidBy=d.UserID ORDER BY a.SaidBy, a.Saidtime)") or die(mysql_error()); EDIT: Ok just updating this as i fixed the error but its coming out in my while loop 4 times rather than just the once. For one of the records. I think its looping it for every 1 message that has occured in the chatlogs for the report and there are 4 in total so its showing it 4 times. Quote Link to comment https://forums.phpfreaks.com/topic/84159-query-finds-same-report-4-times/ Share on other sites More sharing options...
fenway Posted January 2, 2008 Share Posted January 2, 2008 That != in your ON clause will cause problems. Quote Link to comment https://forums.phpfreaks.com/topic/84159-query-finds-same-report-4-times/#findComment-428740 Share on other sites More sharing options...
SirChick Posted January 2, 2008 Author Share Posted January 2, 2008 Ok changed it to = rather than != but still loads 4 of the same thing. Do you want to see my table structure so you can see the logic what im trying to do ? Quote Link to comment https://forums.phpfreaks.com/topic/84159-query-finds-same-report-4-times/#findComment-428792 Share on other sites More sharing options...
fenway Posted January 3, 2008 Share Posted January 3, 2008 You want a single query, just ordered differently... no need for a union here. Quote Link to comment https://forums.phpfreaks.com/topic/84159-query-finds-same-report-4-times/#findComment-429275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.