我有这个疑问;
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 语句,或者是排序问题?
最佳答案
尝试为
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
关于MySQL 查询返回的结果多于应有的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23458192/