请教一个sql语句的问题,菜鸟刚来没多少分数给各位。着急在线等

wsure 2004-10-25 05:45:36
a 表和b表2个表
怎样才能选择出 a表和B中 编号为1的,不同的记录呢?

然后把这些b表中编号为1的,而a表中不存在的插入到a表呢?
...全文
81 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
掌心 2004-10-25
  • 打赏
  • 举报
回复
这样也能查出来啊?
Andy__Huang 2004-10-25
  • 打赏
  • 举报
回复
insert into a select * from b b where text not in(select text from a where id=b.id)
pbsql 2004-10-25
  • 打赏
  • 举报
回复
insert into a(id,[text])
select id,[text] from b
where not exists(select * from a where id=b.id and [text]=b.[text])
lsxaa 2004-10-25
  • 打赏
  • 举报
回复
insert into A
select * from B
where not exists(select 1 from A where id=b.id and text=b.text)
Andy__Huang 2004-10-25
  • 打赏
  • 举报
回复
//怎样才能选择出 a表和B中 编号为1的,不同的记录呢?
select * from a where 编号=1
union
select * from b where 编号=1

//然后把这些b表中编号为1的,而a表中不存在的插入到a表呢?
insert into a select * from b where 编号=1 and 编号 not in(select 编号 from a where 编号=1)
wsure 2004-10-25
  • 打赏
  • 举报
回复
比如a表中字段入下

id text
========
1 ff
1 ada
1 adf
2 ffda
2 eerrr

B表
id text
========
1 ff
1 ada
1 adf
1 ere
2 ffda
2 eerrr


怎么才能把B表中的
1 ere
记录插入到A表呢?
wsure 2004-10-25
  • 打赏
  • 举报
回复
目的就是同步 a表和b表中的 编号为1的记录 (有很多编号为1的记录)
kookboy 2004-10-25
  • 打赏
  • 举报
回复
说明白点,如何还算表A,B记录不同,

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧