为什么这个查询返回companyVisible为0的结果,即使我只要求companyVisible的值为1的公司?
SELECT c.companyID, c.companyDescription , c.companyName ,c.copmanyDrastiriotita, c.companyVisible
FROM company c
WHERE c.companyVisible = 1
AND c.companyDescription LIKE '%Keyword%'
OR c.companyName LIKE '%Keyword%'
OR c.copmanyDrastiriotita LIKE '%Keyword%'
最佳答案
因为或从句
在AND ...OR
子句周围使用括号
用这个
SELECT c.companyID, c.companyDescription , c.companyName ,c.copmanyDrastiriotita, c.companyVisible
FROM company c
WHERE c.companyVisible = 1
AND (c.companyDescription LIKE '%Keyword%'
OR c.companyName LIKE '%Keyword%'
OR c.copmanyDrastiriotita LIKE '%Keyword%')
关于mysql - sql查询返回错误结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38072375/