Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 错误的结果(或where查询)_Mysql_Sql - Fatal编程技术网

Mysql 错误的结果(或where查询)

Mysql 错误的结果(或where查询),mysql,sql,Mysql,Sql,我的查询如下所示: 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 重要的想法是游戏赢家\u用户\u id`!=49。但

我的查询如下所示:

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
重要的想法是游戏
赢家\u用户\u id`!=49
。但我认为这个查询的结果是:

有人可能会告诉我,为什么我收到的结果是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)

您可能需要将
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)

优先于
。因此,您的查询等于:

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;
选择*
来自游戏
prowizja.id_gry=games.id上的内部连接prowizja
其中(games.status=2和games.winner\u user\u id=49和games.owner\u user\u id=49)
或games.join_user_id=49;
你想要它在哪里

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);
选择*
来自游戏
prowizja.id_gry=games.id上的内部连接prowizja
其中(games.status=2和games.winner\u user\u id 49)
和(games.owner\u user\u id=49或games.join\u user\u id=49);

结论:当混合
以及
优先于
时,使用括号。因此,您的查询等于:

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;
选择*
来自游戏
prowizja.id_gry=games.id上的内部连接prowizja
其中(games.status=2和games.winner\u user\u id=49和games.owner\u user\u id=49)
或games.join_user_id=49;
你想要它在哪里

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);
选择*
来自游戏
prowizja.id_gry=games.id上的内部连接prowizja
其中(games.status=2和games.winner\u user\u id 49)
和(games.owner\u user\u id=49或games.join\u user\u id=49);

结论:无论何时混合
都要使用括号,因为您在查询中使用了OR子句。根据您的要求更新您的查询。如果您只想不显示获奖者id 49的记录。您可以使用下面的查询

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)

因为您正在查询中使用or子句。根据您的要求更新您的查询。如果您只想不显示获奖者id 49的记录。您可以使用下面的查询

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)

我的小毛病friend@RiggsFolly:谢谢。我的车有点小毛病friend@RiggsFolly:谢谢。