I have the following table structure:
table_book_user
book_id | user_id
--------+---------
b1 | u1
b3 | u1
b2 | u1
b4 | u2
b5 | u2
b5 | u3
table_book_collection
book_id | collection_id
--------+--------------
b1 | c1
b2 | c1
b3 | c1
b4 | c2
b5 | c1
b5 | c2
b5 | c3
I want to find out which collection a user have. The collection is matched only if a user has all the books of the collection.
For the example above:
u1
is missingb5
to havec1
u2
hasc2
andc3
u3
hasc3
.
So the result should be:
user_id | collection_id
--------+--------------
u2 | c2
u2 | c3
u3 | c3