Im trying to find the most liked photo in my DB. There are PHOTOS,LIKES,USERS tables. I tryed to find most liked photo and user who posted the picture with only LIKES and USERS and got an error.
SELECT
users.username,
photo_id,
COUNT(*) AS most_liked
FROM
likes
INNER JOIN users ON users.id=likes.user_id
GROUP BY
photo_id
ORDER BY
most_liked DESC
LIMIT
1;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ig_clone.users.username' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Can I do this with only 2 tables or should I use 3rd table as well?