table1:
no name city
4 zhang bj
6 li nj
12 zhao dbtable2:
no job name
1 PG qian
4 PL sun
8 PM wu
10 SE wang查询结果如下
no name city job
1 qian PG
4 sun bj PL
6 li nj
8 wu PM
10 wang SE
12 zhao db即查询两个表中的所有字段,当no相同时用table2中的name替换table1中的name。
no name city
4 zhang bj
6 li nj
12 zhao dbtable2:
no job name
1 PG qian
4 PL sun
8 PM wu
10 SE wang查询结果如下
no name city job
1 qian PG
4 sun bj PL
6 li nj
8 wu PM
10 wang SE
12 zhao db即查询两个表中的所有字段,当no相同时用table2中的name替换table1中的name。
解决方案 »
- 请问这个报表 的Sql 写法 有没有规范点的?
- 这个插入存储过程怎么写才正确
- BDE中关于ACCESS97的"General Sql Error",紧急求助!谢谢谢谢
- 请求数据库高手能进群交流搜索这方面的数据库知道谢谢群号:17371752
- 求救ACCESS数据库字段分割统计
- 求解表的问题??在线等谢谢各位高手了!!!
- **********动态列查询***********
- 请教:关于SQL语句?
- 有知道如何估算表存储空间的兄弟吗?
- Binding information is invalid--哪位大佬能解答一下?
- 寻SQL SERVER 2008 R2达人,基础问题(急)
- 求解.SQL2008执行max或min函数时会很慢
from tb join tb2 on tb.no=tb2.nounion select no,name,city,''
from tb t
where not exists(select 1 from tb2 where t.no=tb2.no)union
select no,name,'',job
from tb2 s
where not exists(select 1 from tb where s.no=tb.no)
from tb1 full join tb2 on a.no=b.no
from tb join tb2 on tb.no=tb2.nounion select no,name,city,''
from tb t
where not exists(select 1 from tb2 where t.no=tb2.no)union
select no,name,'',job
from tb2 s
where not exists(select 1 from tb where s.no=tb.no)
isnull(a.no,b.no)no,
isnull(a.name,b,name)name,
a.city,b.job
from
tb1 full join tb2 on a.no=b.no
----------- ---- ---- ----
1 qian NULL PG
4 sun bj PL
6 li nj NULL
8 wu NULL PM
10 wang NULL SE
12 zhao db NULL(6 row(s) affected)
isnull(a.no,b.no)no,
isnull(a.name,b,name)name,
a.city,b.job
from
tb1 full join tb2 on a.no=b.no