MySQL文档有一个很好的页面,其中包含有关哪些运算符优先的信息。
在该页面上,
12.3.1。运算符优先级
运算符优先级从最高优先级到最低优先级显示在以下列表中。一起显示在一行上的运算符具有相同的优先级。
INTERVALBINARY, COLLATE!- (unary minus), ~ (unary bit inversion)^*, /, DIV, %, MOD-, +<<, >>&|= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, INBETWEEN, CASE, WHEN, THEN, ELSENOT&&, ANDXOR||, OR= (assignment), :=
所以你原来的查询
Select *from tablename where display = 1 or display = 2 and content like "%hello world%" or tags like "%hello world%" or title = "%hello world%"
将被解释为
Select *from tablename where (display = 1) or ( (display = 2) and (content like "%hello world%") ) or (tags like "%hello world%") or (title = "%hello world%")
如有疑问,请使用括号将您的意图弄清楚。虽然MySQL页面上的信息很有帮助,但如果再次访问该查询,可能不会立即显而易见。
您可能会考虑以下内容。请注意,我已将更改
title = "%hello world%"为
title like "%helloworld%",因为它更适合您所描述的目标。
Select *from tablename where ( (display = 1) or (display = 2) ) and ( (content like "%hello world%") or (tags like "%hello world%") or (title like "%hello world%") )



