#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Posts
    67
    Rep Power
    0

    Mysql query help need


    Hi to all,

    I have product table and product_feature table I want to get the product which has specific feature e.g

    Code:
    product_table
    ==========
    product_id       product_name
    1                       abc
    2                       def
    3                       ghi
    
    product_feature
    ============
    feature_id          product_id       feature_value
    1                         1                       1
    2                         1                       2
    3                         1                       3
    2                         2                       2
    3                         2                       3
    4                         2                       4
    Basically in product _feature table the feature_id is not unique it is grande between product and feature but because of some reason i delete the primary key of product_feature to store multiple value

    Now i want to get the product which has feature_value (1,2,3)

    please help
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,178
    Rep Power
    4274
    Code:
    SELECT product_id
      FROM product_feature
     WHERE feature_value IN (1,2,3)
    GROUP
        BY product_id 
    HAVING COUNT(*) = 3
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo