MySQL查询返回的结果多于应有的结果

时间:2014-05-04 15:46:38

标签: 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语句,还是排序问题?

1 个答案:

答案 0 :(得分: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