MYSQL中在select時對NULL值的發現

MYSQL中,在select時對兩個同爲NULL值的字段竟然不匹配。記錄一下。




drop table if exists test1 ;
create table test1
(
id int (11),
name char(20)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

drop table if exists test2 ;
create table test2
(
id int (11),
name char(20)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

insert into test1 values( 1,'javaliujie' ) ;
insert into test1 values( 2,NULL ) ;
insert into test1 values( 3,NULL ) ;
insert into test1 values( 4,'' ) ;
insert into test1 values( 5,'' ) ;

insert into test2 values( 1,'javaliujie' ) ;
insert into test2 values( 2,NULL ) ;
insert into test2 values( 3,NULL ) ;
insert into test2 values( 4,NULL ) ;
insert into test2 values( 5,'' ) ;


mysql> select * from test1,test2 where test1.id=test2.id and test1.name=test2.name ;
+------+------------+------+------------+
| id | name | id | name |
+------+------------+------+------------+
| 1 | javaliujie | 1 | javaliujie |
| 5 | | 5 | |
+------+------------+------+------------+
2 rows in set (0.00 sec)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章