How can I write a MySQL query to check multiple rows?
- by Matt
I have a MySQL table containing data on product features:
feature_id feature_product_id feature_finder_id feature_text feature_status_yn
1 1 1 Webcam y
2 1 1 Speakers y
3 1 1 Bluray n
I want to write a MySQL query that allows me to search for all products that have a 'y' feature_status_yn value for a given feature_product_id and return the feature_product_id. The aim is to use this as a search tool to allow me to filter results to product IDs only matching the requested feature set.
A query of SELECT feature_id FROM product_features WHERE feature_finder_id = '1' AND feature_status_yn = 'y' will return all of the features of a given product. But how can I select all products (feature_product_id) that have a 'y' value when they are on separate lines?
Multiple queries might be one way to do it, but I'm wondering whether there's a more elegant solution based purely in SQL.