VERSION 我正在使用服务器版本:5.1.36-community-log MySQL Community Server (GPL)
我终于设计了一个简单的例子来轻松重现它!
设置:
create table t1(id integer unsigned,link integer unsigned);
create table t2(id integer unsigned auto_increment,primary key(id));
create table t3(id integer unsigned,content varchar(30));
insert into t1 value(1,null);
insert into t2 value(1);
insert into t3 value(1,'test');
然后运行:
select t2.*,t3.*
from t1
left join t2 on t1.link=t2.id
left join t3 on t3.id=t2.id
where t1.id=1;
会错误地得到这个:
+------+------+---------+
| id | id | content |
+------+------+---------+
| NULL | 1 | test |
+------+------+---------+
但是如果我们以这种方式创建 t2,它就不会发生:
create table t2(id integer unsigned);
所以,它与主键有关!
新发现
运行它不会触发错误:
select t2.*,t3.*
from t1
left join t2 on t1.link=t2.id
left join t3 on t2.id=t3.id
where t1.id=1;
所以它也与加入方向有关!