MySQL的操作顺序对于IN参数

时间:2012-10-05 16:10:12

标签: mysql query-parameters

  

可能重复:
  Mysql or/and precedence?

如果我有一个如下所示的查询:

SELECT * 
  FROM `users`
 WHERE 'gen'='0' OR `gen`='1' AND `id` IN ('405','406','407',...),

它会返回用户的结果(gen ='0'或gen ='1')和(id IN(...),还是其他一些结果?如果有,我可以加括号围绕条款分开?

感谢。

1 个答案:

答案 0 :(得分:0)

尝试,

SELECT * 
FROM `users`
WHERE `gen` IN (0, 1) AND 
      `id` IN ('405','406','407',...)

相同
SELECT * 
  FROM `users`
 WHERE (`gen`='0' OR `gen`='1') AND 
        `id` IN ('405','406','407',...)