sql 删除和添加记录

hncdllyz 2014-09-09 12:13:14
表一
id
12
22
33
28
表二
id group
12 1
22 1
33 2
28 2
39 3

1 如何删除表一中第2组的成员
2 如何添加表一中第3组的成员,并且,反复添加无效
...全文
124 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hncdllyz 2014-09-10
  • 打赏
  • 举报
回复
把分给mathsfan吧
mathsfan 2014-09-09
  • 打赏
  • 举报
回复
insert into 表一(id) select id from 表二 where group='3' and not exists(select a.id from 表一 a left join 表二 b where a.id=b.id and b.group='3') group by id
mathsfan 2014-09-09
  • 打赏
  • 举报
回复
delete 表一 where id in(select id from 表二 where group='2')
mathsfan 2014-09-09
  • 打赏
  • 举报
回复
delete 表一 where iid='22'
hncdllyz 2014-09-09
  • 打赏
  • 举报
回复
抱歉,在管理器中通不过,试了一下,这样好像可以 insert into 表一(ID) select b.ID from 表二 b where b.group =3 and not exists(select 1 from 表一 a where a.ID= b.ID)
Blessed_Chuan 2014-09-09
  • 打赏
  • 举报
回复
引用 3 楼 mathsfan 的回复:
insert into 表一(id) select id from 表二 where group='3' and not exists(select a.id from 表一 a left join 表二 b where a.id=b.id and b.group='3') group by id
正解
hncdllyz 2014-09-09
  • 打赏
  • 举报
回复
谢谢 mathsfan 下午验证成功以后结题

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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