小冰冰传奇攻略app:sql问题,请帮帮忙啊

来源:百度文库 编辑:中科新闻网 时间:2024/05/05 00:44:29
我想选出两个表不同的记录,然后在一个表中显示
如何编写sql语句
例:table1 id name table2 id riqi
a b a c
d e f g
我的目的是 table3 id name riqi
d e null
f null g
这样可以吗

不同的记录是指什么?
两表中均存在的,但各栏位不同的值?
是否包含在另外一个表中不存在的记录?

使用集合运算,你看能否满足你的兴趣:
select col1,col2,... from A
where (col1,col2,...) not in
(select col1,col2,... from A
intersect
select col1,col2,... from B)
union
select col1,col2,... from B
where (col1,col2,...) not in
(select col1,col2,... from A
intersect
select col1,col2,... from B)

最简单的是用表联接
select table1.column1,table1.column2...,table2.colum1,table2.colum2...
from table1 inner join table2
on
table1.column=table2.column
where 条件

还可以是left join和right join

select table1.id,name,riqi from tabl1 inner join tabl2
on
tabl1.id=tabl2.id

这样就差不多了,但是你说的"d e null f null g "是什么意思,没看明白.
如果你想不显示tabl2 中没有的数据就用right join

backup database 数据库 to disk='\\user01\共享目录名\备份
with 服务器名='sqlserver'all 客户机名='user01'