如何连接两条查询同时进行一个查询

vus520 2008-01-20 07:14:21
现在有多个Access数据库,以后会转为MSSQL,不知道执行以下语句哪个方便一些?

一,根据书的名字取得书的ID

SQL codeselect id from bookid where bookname="书的名字"

二,根据刚刚取得的 书的ID ,在第二张表中更新书的内容:

SQL codeupdate content set bookid='书的ID' where bookname="书的名字"


其实两句SQL可以连接在一起使用,可是我不会,组合的SQL出现错误"必须使用一个可更新的查询"

组合如下:

SQL codeupdate content set bookid=(select id from bookid where bookname="书的名字") where bookname="书的名字"


不知道这语句语法错误在哪里,请高手给一个正确的写法!
...全文
125 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengxuan 2008-01-21
  • 打赏
  • 举报
回复
是不是应该这样写


update content set bookid=(select TOP 1 id from bookid where bookname="书的名字") where bookname="书的名字"
ZoarYang 2008-01-20
  • 打赏
  • 举报
回复
Vus520 这个得帮你顶上去
locoy 2008-01-20
  • 打赏
  • 举报
回复
接分
vus520 2008-01-20
  • 打赏
  • 举报
回复
快疯了,有没有朋友帮忙解决一下,Access的数据库
locoy 2008-01-20
  • 打赏
  • 举报
回复
楼上的这句SQL明显错误呀...
eclipse13 2008-01-20
  • 打赏
  • 举报
回复
update content set bookid='书的ID' where bookname = (select id from bookid where bookname = "书的名字")

locoy 2008-01-20
  • 打赏
  • 举报
回复

update content set bookid=bookid.id from content a,bookid b on content.bookid=bookid.id
where content.bookname='满天星'


不知道是不是正确的,在Access中执行提示 From 这里出现错误.
wzy_love_sly 2008-01-20
  • 打赏
  • 举报
回复
update content set bookid=b.id from content a,bookid b on a.bookid=b.id
where a.bookname='书的名字'
locoy 2008-01-20
  • 打赏
  • 举报
回复
SQL codeupdate content set bookid=(select id from bookid where bookname="书的名字") where bookname="书的名字"

谁知道这语句是错在哪呢.我有时也遇到这个问题.帮忙随便回答一下.
locoy 2008-01-20
  • 打赏
  • 举报
回复
一楼和二楼的SQL真是有点看不懂呢.
vus520 2008-01-20
  • 打赏
  • 举报
回复
不知道在Access中执行的话,应该怎么写?
pt1314917 2008-01-20
  • 打赏
  • 举报
回复

一,根据书的名字取得书的ID
select id from bookid where bookname="书的名字"
二,根据刚刚取得的 书的ID ,在第二张表中更新书的内容:
update content set bookid='书的ID' where bookname="书的名字"
------------------------------------------
update content set bookid=b.id from content a,bookid b
where a.bookname=b.bookname and a.bookname='书的名字'

-狙击手- 2008-01-20
  • 打赏
  • 举报
回复
1===========

declare @bookid int

select @bookid = id from bookid where bookname='书的名字'

codeupdate content set bookid = @bookid where bookname='书的名字'


2====

update t
set t.bookid= b.id
from content t
left join bookid b on t.bookname = b.bookname
where t.bookname='书的名字'

34,588

社区成员

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

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