I need to find photos in which a user has been tagged in together with other users ten or more times. One photo has many tags and a user belongs to a tag.
For example, John and Jane have been tagged together in ten photos. I need a query which will return those ten photos.
What I have so far:
select count(*) tag_count, tags.user_id from tags
join users on users.id = tags.user_id
where tags.user_id != 1 and photo_id in
(select photo_id from tags where user_id = 1)
group by tags.user_id
having count(tags.id) >= 10
order by tag_count desc;
This returns the tag count of users tagged together in a photo with a specific user (ID: 1) at least ten times, but I am not sure how to adapt this query to get a list of the actual photo records.
Any suggestions would be appreciated.