slj90 Posted December 24, 2014 Share Posted December 24, 2014 I need to add likes_username to this query and use a DISTINCT on it. It currently counts how many likes a status has but in the table there are some statuses with multiple likes from the same username. SELECT s.*, COUNT(l.likes_location_id) AS likeCount FROM stream AS s LEFT JOIN likes AS l ON ( l.likes_location_id = s.stream_id ) GROUP BY s.stream_id ORDER BY s.stream_id DESC LIMIT 50 Many thanks, Link to comment https://forums.phpfreaks.com/topic/293316-help-adding-distinct-to-query/ Share on other sites More sharing options...
Barand Posted December 24, 2014 Share Posted December 24, 2014 You could add COUNT(DISTINCT l.likes_username) as userCount to the select clause Link to comment https://forums.phpfreaks.com/topic/293316-help-adding-distinct-to-query/#findComment-1500574 Share on other sites More sharing options...
Psycho Posted December 24, 2014 Share Posted December 24, 2014 . . . there are some statuses with multiple likes from the same username. Sounds like you are trying to solve the wrong problem. Why are you allowing the same user to "like" the same status multiple times? Link to comment https://forums.phpfreaks.com/topic/293316-help-adding-distinct-to-query/#findComment-1500575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.