select 字段1,'' as 字段2 from tab1 union select '' as 字段1,字段2 from tab2
select a.字段1,a2.字段2 from tab1 a left join tab2 a2 a.某字段=a2.某字段
使用Full Join如: select a.字段1,a2.字段2 from tab1 a full join tab2 a2 a.某字段=a2.某字段
select 字段1,'' as 字段2 from tab1 union all select '' as 字段1,字段2 from tab2
使用完整外部联接:full join 或 full outer join 两表相同的组合在一起,A表有,B表没有的数据(显示为null),同样B表有A表没有的显示为(null) select a.字段1,a2.字段2 from tab1 a full join tab2 a2 on a.某字段=a2.某字段 或者 select a.字段1,a2.字段2 from tab1 a full outer join tab2 a2 on a.某字段=a2.某字段
连接查询有你那么写的么。你那种写法完全没什么意义。 如果是连接查询的话,你没写连接方式,以及where条件,也就相当于查出两个表的数据。 和分别查两个表没区别。 select a.ziduan1 ,a.ziduan2 ,b.ziduan1,b.ziduan2 from a inner join b on a.id=b.a_id where a.id>5 上面是标准的了解查询。 a ,b表间有主外键关系,自己看吧
如果B表的数据A表中一定有,如果A表在左边,就用左连接 Left JOIN 如果B表的数据A表中一定有,如果A表在右边,就用右连接 Right JOIN 如果A表与B表中数据都可能有,则用全连接 FULL JOIN 如果A表与B表数据内容全不同,需交叉显示,则用Cross JOIN。
select a.字段1,a2.字段2 from tab1 a full join tab2 a2 on a.某字段=a2.某字段 内连接 select a.字段1,a2.字段2 from tab1 a full outer join tab2 a2 on a.某字段=a2.某字段 外连接
select 字段1,'' as 字段2 from tab1
union
select '' as 字段1,字段2 from tab2
select a.字段1,a2.字段2 from tab1 a full join tab2 a2 a.某字段=a2.某字段
select 字段1,'' as 字段2 from tab1
union all
select '' as 字段1,字段2 from tab2
两表相同的组合在一起,A表有,B表没有的数据(显示为null),同样B表有A表没有的显示为(null)
select a.字段1,a2.字段2 from tab1 a full join tab2 a2 on a.某字段=a2.某字段
或者
select a.字段1,a2.字段2 from tab1 a full outer join tab2 a2 on a.某字段=a2.某字段
如果是连接查询的话,你没写连接方式,以及where条件,也就相当于查出两个表的数据。
和分别查两个表没区别。
select a.ziduan1 ,a.ziduan2 ,b.ziduan1,b.ziduan2 from a inner join b
on a.id=b.a_id where a.id>5 上面是标准的了解查询。
a ,b表间有主外键关系,自己看吧
如果B表的数据A表中一定有,如果A表在右边,就用右连接 Right JOIN
如果A表与B表中数据都可能有,则用全连接 FULL JOIN
如果A表与B表数据内容全不同,需交叉显示,则用Cross JOIN。
内连接
select a.字段1,a2.字段2 from tab1 a full outer join tab2 a2 on a.某字段=a2.某字段
外连接
应该能满足楼主的需求