2014-05-04 103 views
0

我有這個查詢;MySQL查詢返回比它應該更多的結果

SELECT * FROM (`products`) WHERE `show_in_store` = 1 AND 
`category` = '8' AND `stock` >= 0 AND `name` LIKE '%a%' 
OR `description` LIKE '%a%' ORDER BY `product_id` asc 

應該只返回一個結果很少(那些設置爲8類),但它返回的一切,包括具有不同類別的結果...

是否LIKE功能上寫AND語句,還是訂購問題?

+0

一些括號也許 – Strawberry

回答

1

嘗試爲

SELECT * FROM `products` 
WHERE 
`show_in_store` = 1 
    AND `category` = '8' 
    AND `stock` >= 0 
    AND (`name` LIKE '%a%' OR `description` LIKE '%a%') 
ORDER BY `product_id` asc 
+0

輝煌,謝謝大家。 –