我的查询看起来像:

select *
from `games`
    inner join `prowizja` on `prowizja`.`id_gry` = `games`.`id`
where `games`.`status` = 2 and `games`.`winner_user_id` != 49
 and `games`.`owner_user_id` = 49 or `games`.`join_user_id` = 49


重要的想法是games . winner_user_id`!=49。但是我查询到的结果是:

mysql - 错误的结果(或在哪里查询)-LMLPHP

有人可以告诉我,为什么我收到winner_user_id 49的结果,但我不希望等于。
谢谢

最佳答案

您可能必须将WHERE子句的最后两个谓词放在括号中:

select *
from `games`
inner join `prowizja`
on `prowizja`.`id_gry` = `games`.`id`
where `games`.`status` = 2 and
      `games`.`winner_user_id` != 49 and
      (`games`.`owner_user_id` = 49 or `games`.`join_user_id` = 49)

关于mysql - 错误的结果(或在哪里查询),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37026567/

10-16 00:28