I have a application where users can take images and tag them selfs. Here is the database structure looks like:
For the purpose of this problem lets take three main table that involve:
user, image, user_image
user table
id, user_name, age
1, test1, 23
2, test2, 34
image table
id, users_in_image, datetime
1, test1,test2, 03/01/2000
2, test1, 03/01/2003
user_image table
id, user_id, image_id
1, 1, 1
2, 1, 2
Every time user take an image it creates a record in image, user and user_image, given a user I want to see all users that user has taken images with and what are those image_ids.
Here is my solution
select * from user_image where image_id
in (select image_id from user_image where user_id = '1') and user_id != '1';
I am worried this is not a good solution. I would like to get some thoughts from experts.