I have a database with multiple content types and users, as well as a separate database with likes. I’m trying to figure out which users have received the most likes for any of their content, no matter what the type.
I’ve been able to figure out queries for finding the most liked users by specific content types, but going with any content type is proving to be a bit more difficult.
It might be worth noting that there are millions of records in this database.
Here’s the work I’ve been doing on creating a query… I’m pretty sure it’s not correct!
SELECT picture.user_id, video.creator_id, post.author_id
FROM likes_service.likes
INNER JOIN prod.pictures picture ON likes.obj_id = picture.id
INNER JOIN prod.videos video ON likes.obj_id = video.id
INNER JOIN prod.posts post ON likes.obj_id = post.id
GROUP BY picture.user_id, video.creator_id, post.author_id
ORDER BY COUNT(picture.user_id), COUNT(video.creator_id), COUNT(post.author_id) DESC
LIMIT 20;
Could anybody please give me a hint or point me in the right direction? I feel like I’m getting close…
Thanks!
I think you want a UNION, not a multi-way JOIN.