How can I write a MySQL query to check multiple rows?

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-04-04T12:32:56Z Indexed on 2010/04/04 12:43 UTC
Read the original article Hit count: 298

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about query