Home Forums Programming General SQL - How to group by on two fields and count RE: SQL - How to group by on two fields and count

  • 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).

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **