我正在尝试使用LIKE和!=条件编写查询:
SELECT *
FROM posts
WHERE title LIKE 'term%'
OR NAME LIKE 'term%'
AND post_type != 'type';
但是,查询结果未按post_type过滤。我的语法有问题吗?
您可能需要括号,因为AND
具有运算符优先级。
SELECT *
FROM posts
WHERE ( title LIKE 'term%' OR NAME LIKE 'term%' )
AND post_type != 'type';
因为现在没有括号,您有了
SELECT *
FROM posts
WHERE title LIKE 'term%'
OR ( NAME LIKE 'term%'
AND post_type != 'type' );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句