Suppose I have two tables:
product
-------
productid
name
and
language
--------
productid
code
I have three products:
1, 'homebody' -> 1, EN
2, 'continetnal' -> 2, FR
-> 2, EN
-> 2, ES
3, 'westy' -> 3, EN
-> 3, ES
-> 3, FR
-> 3, PT
4, 'oktoberfest' -> 4, DE
Suppose I have a list of languages I am interested EN, FR, ES in I would like to create three types of query to select a number of products.
- Match any language in my list (‘homebody’, ‘continental’, ‘westy’)
- Match all languages in my list (‘continental’, ‘westy’)
- Match exactly languages in my list (‘continental’)
I think the solution to the first is just:
SELECT * FROM products AS p JOIN language AS l ON (p.productid = l.productid) WHERE l.code IN ('EN', 'ES', 'FR')
What is a good way for me to solve the other queries? I suspect something where I count the number of languages associated with my product and make sure it is equal-to or at-least the number of languages in my query, but not sure how to make this happen.
if you can’t have two times FR (or any language) for the same product :
2.
3.
or if you wanna retrieve languages codes