Mysql WHERE command for multiple values

Discussion in 'MySQL' started by rahulephp, Apr 24, 2010.

  1. #1
    Please help me to find out the solution.
    I want to fetch data from "product" table where "Product_id"(s) are 5,8,9,12...

    I am using the query:
    SELECT * FROM products WHERE product_id=5 OR product_id=7 
    OR product_id=8 
    OR product_id=9 
    OR product_id=12 
    Code (markup):
    But i dont want to use "product_id=" again and again many time.

    Just wondering if there any sql syntax like "SELECT * FROM products WHERE product_id=(5,8,9,12)" ?
    Above statement is only a assumption but wanted to know if there is anything possible like this.

    Thanks in anticipation
     
    rahulephp, Apr 24, 2010 IP
  2. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Got the solution:
    SELECT *
    FROM `products`
    WHERE product_id
    IN ('5','8','9','12');
     
    rahulephp, Apr 24, 2010 IP