关联查询

一 、关联查询( 将查询结果组合为一张新的临时表)
select A.num, B.num as B_num
from A,B
Where A.nid = B.nid
或者:
select A.num, B.num as B_num
from A inner join B
on A.nid = B.nid
二、左关联查询(显示A表中的所有数据,如果B中无对应关系,则值为null)
select A.num, B.num as B_num
from A left join B
on A.nid = B.nid
三、右关联查询(显示B表的所有数据,如果A中无对应关系,则值为null)
select A.num, B.num as B_num
from A right join B
on A.nid = B.nid
四、组合(自动处理重合)
select A.num
from A
union
select B.num
from B
五、 组合(不处理重合)
select A.num
from A
union all
select B.num
from B

你可能感兴趣的:(关联查询)