求一简单SQL

ttyp 2003-10-21 11:58:33
表T1
A B C
1 2 3
2 1 1
3 2 1
4 1 1
表T2
A B C
1 2 3
2 1 1
现在要删除T1中,有和T2一样的记录
结果
T1
3 2 1
4 1 1

...全文
30 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-10-25
  • 打赏
  • 举报
回复
楼主写错了

create table #t1 (a int,b int)
insert into #t1 values(1,1)
insert into #t1 values(2,1)
insert into #t1 values(3,1)
insert into #t1 values(4,1)
create table #t2 (a int,b int)
insert into #t2 values(1,1)
insert into #t2 values(2,1)

delete #t1 where exists(select 1 from #t2 y where a = #t1 .a and b=#t1.b)
select * from #t1

drop table #t1
drop table #t2
lijinqiang 2003-10-25
  • 打赏
  • 举报
回复
delete 表T1 WHERE 第一个字段 NOT IN (SELECT 第一个字段 FROM 表2)
银狐被占用 2003-10-25
  • 打赏
  • 举报
回复
delete t1 join t2 on t1.a=t2.a and t1.b=t2.b and t1.c=t2.c
LoveSQL 2003-10-25
  • 打赏
  • 举报
回复
delete T1 from t1,t2
where t1.a=t2.a and t1.b=t2.b and t1.c=t2.c
welyngj 2003-10-24
  • 打赏
  • 举报
回复
delete t1 where exists(select 1 from t2 where a=t1.a and b=t1.b and c=t1.c)
ttyp 2003-10-24
  • 打赏
  • 举报
回复
----------------
只能是查询,不能够delete
chenzhuo 2003-10-24
  • 打赏
  • 举报
回复
delete t1 where exists(select 1 from t2 where a=t1.a and b=t1.b and c=t1.c)
ttyp 2003-10-24
  • 打赏
  • 举报
回复
寒,有没测试过啊~~~
fjw2002 2003-10-24
  • 打赏
  • 举报
回复
delete t1 where exists(select 1 from t2 where a=t1.a and b=t1.b and c=t1.c)
lvltt 2003-10-24
  • 打赏
  • 举报
回复
同意楼上
sai1691 2003-10-22
  • 打赏
  • 举报
回复
delete table t1 where exists(select 1 from t2 where a=t1.a and b=t1.b and c=t1.c)
gmlxf 2003-10-21
  • 打赏
  • 举报
回复
以下应该可以的:
create table #t1 (a int,b int)
insert into #t1 values(1,1)
insert into #t1 values(2,1)
insert into #t1 values(2,2)
insert into #t1 values(1,2)
insert into #t1 values(4,1)
create table #t2 (a int,b int)
insert into #t2 values(1,1)
insert into #t2 values(2,2)

select * from #t1
select * from #t2
select identity(int,1,1) as id,* into #t3 from #t1
delete from #t3 where id in
(
select id from #t3 y where exists(select 1 from #t2 where a = y.a and b=y.b)
)

select a,b from #t3

drop table #t1
drop table #t2
drop table #t3
gmlxf 2003-10-21
  • 打赏
  • 举报
回复
我的错的。。
gmlxf 2003-10-21
  • 打赏
  • 举报
回复
create table #t1 (a int,b int)
insert into #t1 values(1,1)
insert into #t1 values(2,1)
insert into #t1 values(3,1)
insert into #t1 values(4,1)
create table #t2 (a int,b int)
insert into #t2 values(1,1)
insert into #t2 values(2,1)

delete #t1 where a in(select y.a from #t2 y) and b in(select y.b from #t2 y)

drop table #t1
drop table #t2
ttyp 2003-10-21
  • 打赏
  • 举报
回复
create table #t1 (a int,b int)
insert into #t1 values(1,1)
insert into #t1 values(2,1)
insert into #t1 values(3,1)
insert into #t1 values(4,1)
create table #t2 (a int,b int)
insert into #t2 values(1,1)
insert into #t2 values(2,1)

delete #t1 where exists(select 1 from #t2 y where a = y.a and b=y.b)
select * from #t1

drop table #t1
drop table #t2

--好象有点问题
yujohny 2003-10-21
  • 打赏
  • 举报
回复
delete T1 where exists(select 1 from T2 where a=T1.a and b=T1.b and c=T1.c)
pengdali 2003-10-21
  • 打赏
  • 举报
回复
delete t1 where exists(select 1 from t2 where a=t1.a and b=t1.b and c=t1.c)
pengdali 2003-10-21
  • 打赏
  • 举报
回复
delete t1 where a in (select a from t2)
pengdali 2003-10-21
  • 打赏
  • 举报
回复
select * from t1 where a not in (select a from t2)
txlicenhe 2003-10-21
  • 打赏
  • 举报
回复
Delete A
from T1 a
join T2 b on a.A = b.A and a.B = b.B and a.C = b.C
加载更多回复(6)

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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