Hi,
I have three tables :
- table item (id_item, title)
- table keyword (id_keyword, word)
- table item_keyword (id_item_keyword, id_item, id_keyword)
So, an item can be associated with 0 to n keywords, and a keyword with 0 to n items.
My purpose : finding the items who are associated with AT LEAST every keywords (id given).
Exemple : I'm giving as a parameter the ids 2,3,5. Item A is associated with keywords with ids 2,3,5,8 : it should be returned. Item B is associated with keywords ids 2,3,24,36 : it should not be returned.
If i make a simple join on id_item, and then an "IN" for the ids, it's an "OR" on the ids, i'd like an "AND".
Code:
SELECT DISTINCT it.id_item, it.title
FROM item it INNER JOIN item_keyword ik ON it.id_item = ik.id_item
WHERE ik.id_keyword IN (2,3,5)
Thanks
|