phpMyAdmin 对我的 UNION ALL 查询做了什么?

What is phpMyAdmin doing to my UNION ALL query?

以下查询 returns 1 行:

SELECT `coach_id` FROM `table_a` WHERE `coach_id` = 8
UNION ALL
SELECT `coach_id` FROM `table_b` WHERE `coach_id` = 8

但是SELECT coach_id FROM table_b WHERE coach_id = 8 returns 2行。

SELECT coach_id FROM table_a WHERE coach_id = 8 returns 1行。

我正在使用 UNION ALL 来避免 DISTINCT 过滤,因为我实际上只对总行数感兴趣。它似乎仍然表现得像常规 UNION a.k.a UNION DISTINCT.

这是怎么回事?查询在 MariaDB 10.1.9 服务器上的 phpMyAdmin 4.5.2 界面中执行。

更新

我刚刚发现 mysql 命令行客户端的行为符合预期。所以失败必须在我的 nginx 1.8.0PHP 5.6.16 mysqliphpmyadmin.

堆栈中的某个地方

更新 2

当我从 php 脚本(使用 mysqli)运行 查询时,它也正确 returns 3 行。我想除了 phpMyAdmin 之外别无他法导致这种现象。感谢到目前为止的帮助,很抱歉这个问题具有误导性。我不知道更好...

架构

create schema testThenDrop123;
use testThenDrop123; -- use that database

create table table_a
(   id int auto_increment primary key,
    coach_id int not null
);

create table table_b
(   id int auto_increment primary key,
    coach_id int not null
);

insert table_a (coach_id) values (8);
insert table_b (coach_id) values (8),(8);

查询

SELECT `coach_id` FROM `table_a` WHERE `coach_id` = 8 
UNION ALL 
SELECT `coach_id` FROM `table_b` WHERE `coach_id` = 8;
+----------+
| coach_id |
+----------+
|        8 |
|        8 |
|        8 |
+----------+

.

drop schema testThenDrop123; -- cleanup by dropping db

所以我看不到你看到的。

您是否有脏数据? ID 中的空格或其他字符?在查询中使用 LENGTH(coach_id), coach_id 。然后,如果它超过一个字符,它不会 return 那些行,但你会知道为什么。

这是一个 phpMyAdmin 错误,已在 v4.5.3.0 (2015-12-23) 中修复。