我在条件查询下方执行多列搜索
SELECT
prod.pid,
prod.pname,
prod.description,
prod.status,
foto.set_cover,
foto.filename
FROM products prod
INNER JOIN second_child_categories secd ON prod.category_id = secd.second_id
INNER JOIN photos foto ON prod.pid = foto.pid
WHERE CONCAT( prod.pname, prod.description ) LIKE '%home%'
OR CONCAT( prod.description, prod.pname ) LIKE '%home%'
AND foto.set_cover = '1'
AND prod.status = '1'
ORDER BY prod.created_date DESC
这是输出:
参考查询,我设置条件:
foto.set_cover='1' AND prod.status='1'
结果与条件不符。
如何修复此查询?
感谢。
答案 0 :(得分:0)
OR
具有更高的优先级,你(隐含地)写道:
CONCAT( prod.pname, prod.description ) LIKE '%home%'
OR (
CONCAT( prod.description, prod.pname ) LIKE '%home%'
AND foto.set_cover = '1'
AND prod.status = '1'
)
我认为你的意思
(
CONCAT( prod.pname, prod.description ) LIKE '%home%'
OR
CONCAT( prod.description, prod.pname ) LIKE '%home%'
)
AND foto.set_cover = '1'
AND prod.status = '1'