Your problem basically lies within the design of the table. If possible you should normalize the table and remove the 'duplicate' columns (User1, User2) and replace them with a single column (User). See more about normalization in Stairway to Database Design Level 9: Normalization[/url]. With a normilized table you can return the desired result with a single GROUP BY (and without a UNION).