簡體   English   中英

sql查詢以獲取結果與排除選定的ID

[英]sql query to get result with exclude selected id

我陷入了SQL查詢。 我想從單個表中選擇產品,但不包括所選產品。 我有wp_product表作為

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' AND prod_price <=200 OR prod_rate='6'  OR 
          order by product_id DESC 
          LIMIT 4"

使用select * from wp_products where product_id <>'1'; 我得到結果

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

從以上結果中,我希望選擇(檢查)我在嘗試查詢中使用的所有“ OR”條件。

建議我如何得到這個。

如果我對您的理解正確,請使用括號:

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

嘗試下面的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM