sql查询联合修改

denbes 2010-10-20 10:16:58
数据库a(int a1,int a2 ,varchar(50) a3)与
数据库b(int b1,int b2 ,varchar(50) b3)
查询出a数据库中a1=b1的记录同时将b3更新a3所返回表.

比如
------------a表----------------------------
1 11 "a"
2 22 "b"
3 33 "c"

------------b表----------------------------
4 11 "aa"
2 22 "bb"
5 33 "cc"

结果------------c表------------------------
2 22 "bb"


最好是SQL语句,同时修改只是在内存中进行,不可以修改两个表.
...全文
363 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
popoisApig 2010-10-21
  • 打赏
  • 举报
回复

不错
[Quote=引用 9 楼 chen8410 的回复:]
SQL code
select b.*
into c --结果生成表c
from a , b
where a.a1 = b.b1

update b --用a表更新b表
set b.b3=a.a3
from a
where a.a1 = b.b1
[/Quote]
fengyun142415 2010-10-21
  • 打赏
  • 举报
回复
相当于查表b中满足条件的数据?

select b.*
from a,b
where a.a1 = b.b1
午夜恋曲 2010-10-21
  • 打赏
  • 举报
回复
学习中!!~
diyppfei 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 fredrickhu 的回复:]
引用 6 楼 denbes 的回复:
引用 4 楼 fredrickhu 的回复:
同时将b3更新a3所返回表是什么意思?

查询出a数据库中a1=b1的记录
同时将b3=a3


SQL code
update c set c3 = b.b3 from c , a , b where c.c1 = a.a1 and a.a1 = b.b1
[/Quote]
update a
set a.a3=b.b3
from b
where a.a1=b.b1

select a.*
into c
from a,b
where a.a1=b.b1
chen8410 2010-10-20
  • 打赏
  • 举报
回复
select  b.* 
into c --结果生成表c
from a , b
where a.a1 = b.b1

update b --用a表更新b表
set b.b3=a.a3
from a
where a.a1 = b.b1

--小F-- 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 denbes 的回复:]
引用 4 楼 fredrickhu 的回复:
同时将b3更新a3所返回表是什么意思?

查询出a数据库中a1=b1的记录
同时将b3=a3
[/Quote]
update c set c3 = b.b3 from c , a , b where c.c1 = a.a1 and a.a1 = b.b1
dawugui 2010-10-20
  • 打赏
  • 举报
回复
--1
select a.* , b.* from a , b where a.a1 = b.b1

--2
update c set c3 = b.b3
from c , a , b
where c.c1 = a.a1 and a.a1 = b.b1
denbes 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 fredrickhu 的回复:]
同时将b3更新a3所返回表是什么意思?
[/Quote]
查询出a数据库中a1=b1的记录
同时将b3=a3
「已注销」 2010-10-20
  • 打赏
  • 举报
回复
select * from
(select a.a1,b.b2 from a,b where a.a1=b.b1)
into c
--小F-- 2010-10-20
  • 打赏
  • 举报
回复
同时将b3更新a3所返回表是什么意思?
--小F-- 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 josy 的回复:]
SQL code
select b.b1,b.b2,b.b3 as a3
from a,b
where a.a1=b.b1


不知道你说的是不是这个意思
[/Quote]

貌似是两个数据库
百年树人 2010-10-20
  • 打赏
  • 举报
回复
select b.b1,b.b2,b.b3 as a3
from a,b
where a.a1=b.b1


不知道你说的是不是这个意思

34,576

社区成员

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

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