2012-12-08 79 views
1

我堅持與SQL查詢。 我想從單個表中選擇產品,但不包括所選產品。 我有wp_product表作爲SQL查詢得到的結果與排除選定的ID

product_id prod_name prod_price prod_rate 
    1   xyz   100   5 
    2   pqr   200   6 
    3   lmn   300   6 

我試圖用這個select * from wp_products where product_id <>'1';我得到的結果

product_id prod_name prod_price prod_rate 
    2   pqr   200   6 
    3   lmn   300   6 

從這個上面的結果,我想選擇執行此查詢

select * 
from wp_products 
where product_id <>'1' AND prod_price <=200 OR prod_rate='6' OR 
      order by product_id DESC 
      LIMIT 4" 

(檢查)所有「或」條件,我用我的試用查詢。

建議我如何得到這個。

回答

1

如果我正確認識你 - 只是用括號:

select * 
from wp_products 
where product_id <>'1' AND 
    (price<=200 OR wheel_size='6' OR studs='$studs') 
order by product_id DESC 
+0

:是的,我到底要this.Thanks – Kango

0

嘗試下面的SQL ..

select * from wp_products 
where (product_id <>'1') AND (price<=200 OR wheel_size='6' OR studs='$studs') 
order by product_id DESC LIMIT 4