Skip to content
Advertisement

SQL: Select only rows fullfilling conditions via relation table

I have two tables and I need to select values from first only when all certain conditions are met in second table. Let explain more on an example.

First table

Second table

And from those tables I need to find out only movies, that user 1 and 3 have seen. So in result I need to see

Wanted result

I tried some queries, but cannot get a grasp of final result. In the end I will be “construncting” this query based on users selected as input. So in the end, there might be as well 5 users and I will need to find only movies, all of them have seen. So please bear that in mind.

All help and ideas are appreciated, thanks.

Advertisement

Answer

You can try below –

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement