How can I select the book Id that is listed under every category id I provide as a set of category Ids
e.g
I want to get the book Ids that are listed under all categories I listed here:
(A,B,C,D,…etc) and not that are listed under any of them.
the following select statement does not work with my query’s conditions:
SELECT bookId
FROM bookCategories
WHERE categoryId IN (‘A’,’B’,’C’,’D’,…..);
because it retrieves the books that are listed under any of the specified categories.
Thanks for any help..
you can use
IN& also check that the number of distinct categories for each book is the same as the number of categories you supplied in yourINpredicate:If you don’t know how many categories you have, you can create a temp table
#CAT(categoryId), populate it with your categories and run the folowing query: