ON子句中不可能的WHERE条件

时间:2013-11-07 22:27:28

标签: mysql

我在mysql上遇到问题,我根据ONLEFT JOIN子句中的条件得到'不可能的WHERE条件'。我在mysql版本5.1.47中有这个错误但在5.1.52中没有。

CREATE TABLE IF NOT EXISTS test.magic_table1 (
    id int primary key,
    val int,
    key (val)
);

CREATE TABLE IF NOT EXISTS test.magic_table2 (
    id int primary key,
    val int,
    key (val)
);

insert into test.magic_table1 values ( 1, 1 );
insert into test.magic_table2 values ( 0, 0 );

/* explain */
select *
from test.magic_table1 m1
left join test.magic_table2 m2
on m1.id = m2.val
and m1.val = 0
where m1.id = 1;

在MySQL 5.1.52上,它返回:

1 | 1 | NULL | NULL

在MySQL 5.1.47上返回空集。

这应该像我想象的那样工作,或者这个查询的编写方式有什么问题吗?由于MySQL在不同版本中的反应方式存在差异,因此这很难追查。

1 个答案:

答案 0 :(得分:2)

mysql中报告了一个错误。

http://bugs.mysql.com/bug.php?id=53334

通过它。对你有所帮助。

相关问题