开发者

Nested Queries? -> Set Value = (Select Value From OtherTable WHERE)

开发者 https://www.devze.com 2023-01-06 05:56 出处:网络
I\'m looking to do a single query to update a database.Here is some pseudocode: UPDATE Table1 SET Table1.Value = (SELECT Value FROM Table2 WHERE Table2.Id==2) WHERE Ta开发者_运维百科ble1.Id == 4

I'm looking to do a single query to update a database. Here is some pseudocode:

UPDATE Table1 SET Table1.Value = (SELECT Value FROM Table2 WHERE Table2.Id==2) WHERE Ta开发者_运维百科ble1.Id == 4


This will only work if your subquery (SELECT Value FROM Table2 WHERE Table2.Id=2) only returns one value. Also replace the == with = in your subquery as I have.

I believe updating it to what I have below would make it work no matter what:

(SELECT Top (1) Value FROM Table2 WHERE Table2.Id=2)

0

精彩评论

暂无评论...
验证码 换一张
取 消