I have this three tables:
products TABLE:
id:integer
name:string
features TABLE:
id:integer
name:string
features_products TABLE:
product_id:integer
feature_id:integer
The features_products TABLE tells me which features have each product. For example:
product_id feature_id
1 3
1 5
3 4
tells me the product 1 has features 3 and 5 and product 3 have feature 4, also, product 2 (if exists) doesn’t have features.
My question is, how can I SELECT all the products from the products TABLE wich have determinated features? For example, SELECT products which have features 3 AND 5, or SELECT products which have feature 2
To select all the product ids for products which have both features 3 and 5:
This assumes that there is a uniqueness contraint on (product_id, feature_id). If you want the entire row from the product table then use this in a subquery: