久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQL 更新查詢和“子查詢返回多個值"

SQL update query and #39;subquery returned more than one value#39;(SQL 更新查詢和“子查詢返回多個值)
本文介紹了SQL 更新查詢和“子查詢返回多個值"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用的是 SQL Server 2008, R2.有一個主表(表 A),我正在嘗試使用臨時表(表 B)中的值更新它.

I am using SQL Server 2008, R2. Have a master table (table A), and am trying to update it with values from a temp table (Table B).

SQL Server 出錯,說子查詢返回了多個值,但是我不明白這是怎么可能的,因為子查詢返回的值是表 B 的主鍵.

SQL Server is erroring out, saying that the subquery returned more than one value, however I don't see how this is possible since the value returned by the subquery is the primary key of Table B.

這是查詢:

UPDATE TableA  
   SET TableA.field = (SELECT TableB.field  
                         FROM TableA 
                   INNER JOIN TableB ON TableA.key = TableB.key) 

非常感謝任何幫助,像往常一樣!

Any assistance greatly appreciated, as usual!

推薦答案

您的子查詢根本不相關.子查詢中的標識符TableA.key"指的是子查詢的 FROM 子句中的 TableA,而不是更新的目標表(恰好也是 TableA).您不想使用兩表連接的結果集更新 TableA.field.你只是想要這個:

Your subquery is not correlated at all. The identifier "TableA.key" in the subquery refers to the TableA in the subquery's FROM clause, not the target table of the update (which happens also to be TableA). You don't want to update TableA.field with the result set of a two-table join. You simply want this:

UPDATE TableA  
   SET TableA.field = (SELECT TableB.field  
                       FROM TableB
                       WHERE TableA.key = TableB.key)

這篇關于SQL 更新查詢和“子查詢返回多個值"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 精品一区二区三区在线观看国产 | 亚洲精品久久久一区二区三区 | 一区二区三区四区毛片 | 中文在线一区 | 欧美8一10sex性hd | 免费一区 | 国产欧美精品区一区二区三区 | 国产精品永久久久久久久www | 亚洲精品一区二区三区在线 | 成人综合视频在线观看 | 一区二区三区在线观看视频 | 精品一区二区电影 | 亚洲欧美国产精品久久 | 久久人爽 | 日韩a视频| 亚洲网站免费看 | 精品日韩在线 | 中文字幕欧美日韩一区 | 欧洲精品久久久久毛片完整版 | 国产一级片免费看 | 中文字幕亚洲国产 | 国产精品久久久亚洲 | 日韩一区二区三区在线 | a在线视频| 国产精品永久久久久 | 天天干天天想 | 香蕉久久久 | 国产精品视频在线观看 | 波多野结衣精品在线 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | 成人精品一区二区三区四区 | 精产国产伦理一二三区 | 欧美一区二区在线观看 | 午夜影院污 | 中文字幕1区2区 | 99热播精品 | 国产成人久久精品 | 久草视频在 | 精品不卡| 亚洲一区二区av | 亚洲网址在线观看 |