join连接的困惑,请帮帮我吧!
两个表,这是第一个表(pers)的字段和数据;
nmaes addr age code
王成兵绵阳251
刘德华香港550
刘和在日本331
吴达在中国441
李知在广东341
这是第二个表(perss)的字段和数据.
nmaes addr age code
李鹏小四川341
周小庆东海341
吴小后北京560
郭小中台湾430
瘟神人广东231
我用这条语句,
select * from pers as a join perss as b on(a.code=b.code) where a.code= '1 ' or b.code= '1 '
本想得到code=1的内容显示出来,而结果去是他的笛卡尔值,为什么呢!
这是用上面那条语句得到的结果:
nmaes addr age code nmaes addr age code
王成兵绵阳251李鹏小四川341
王成兵绵阳251周小庆东海341
王成兵绵阳251瘟神人广东231
刘和在日本331李鹏小四川341
刘和在日本331周小庆东海341
刘和在日本331瘟神人广东231
吴达在中国441李鹏小四川341
吴达在中国441周小庆东海341
吴达在中国441瘟神人广东231
李知在广东341李鹏小四川341
李知在广东341周小庆东海341
李知在广东341瘟神人广东231
请帮我指出这条语句的错误!
谢谢!
[解决办法]
select * from pers where code=1
unoin
select * from perss where code=1
[解决办法]
select * from pers where code = 1
union all
select * from perss where code = 1