日期:2014-05-18  浏览次数:20439 次

请教一个关于组合查询的问题!
table   a
col1   col2   col3   col4
1           1         1         1
2           2         2         2
3           3         3         3

table   b

col1   col2   col3   col4   col5
1           1         1         1         a1
d           c         f       e           g
2           2         2         2         a2
3           3         3         3         a3

如何得到
col1   col2   col3   col4   col5
1           1         1         1       a1
2           2         2         2       a2
3           3         3         3       a3
table   b中第二行为不规则数据,需剔除
table   a中为提出不规则数据后的表,但没有col5字段

------解决方案--------------------
用 left join 。


select A.*,B.col5
from A
left join B on A.col1 =B.col1 and A.col2=B.col2 and A.col3=B.col3 and A.col4=B.col4
------解决方案--------------------
select A.*,B.col5
from A left join B on A.col1 =B.col1 and A.col2=B.col2 and A.col3=B.col3 and A.col4=B.col4会出现A有B没有的值

简单的可以用
select A.*,B.col5
from A,B where A.col1 =B.col1 and A.col2=B.col2 and A.col3=B.col3 and A.col4=B.col4

不过表大效率不高,还是用inner join