coolgeek1987
Programmer
I've got a user table and a book table, with a fact table recording the books read by each user. For simplicity, the tables and their fields are:
Table Fields
----- ------
user user_id
book book_id
books_read user_id, book_id
I have a web app that lets a user select a list of books from a dropdown menu, resulting in a string that looks like "book_id1, book_id2, book_id3..."
I want my app to search the books_read table to present the user_id of all users who read the entire set of books in that string.
Is there an elegant way to do this in SQL, or do I have to parse the string and build my SQL statement on the fly along the lines of:
select user_id
from books_read
where book_id = book_id1
intersect
select user_id
from books_read
where book_id = book_id2
intersect
select user_id
from books_read
where book_id = book_id3
...
thanks
Table Fields
----- ------
user user_id
book book_id
books_read user_id, book_id
I have a web app that lets a user select a list of books from a dropdown menu, resulting in a string that looks like "book_id1, book_id2, book_id3..."
I want my app to search the books_read table to present the user_id of all users who read the entire set of books in that string.
Is there an elegant way to do this in SQL, or do I have to parse the string and build my SQL statement on the fly along the lines of:
select user_id
from books_read
where book_id = book_id1
intersect
select user_id
from books_read
where book_id = book_id2
intersect
select user_id
from books_read
where book_id = book_id3
...
thanks