0
我試圖從另一個更新一個表使用字段:相關更新
Update x
From y
Set 1=y.1, 2=y.2, 3=y.3
Where y.4="*Cash*" and y.5="*Use*"
這可能嗎?或者我必須使用Inner Join還是Subquery?我的更新語法中出現錯誤:「缺少或無效的選項」。
我試圖從另一個更新一個表使用字段:相關更新
Update x
From y
Set 1=y.1, 2=y.2, 3=y.3
Where y.4="*Cash*" and y.5="*Use*"
這可能嗎?或者我必須使用Inner Join還是Subquery?我的更新語法中出現錯誤:「缺少或無效的選項」。
你似乎會問這樣的事情
UPDATE x
SET (col1, col2, col3) = (select y.col1, y.col2, y.col3
from y
where y.col4 = '*Cash*'
and y.col5 = '*Use*')
通常情況下,將是涉及的表x
和y
一些附加條件。如果針對y
的查詢返回單個行,並且您想用該單行數據更新每行x
,則這不是必需的。但通常情況下,你必須像
UPDATE x
SET (col1, col2, col3) = (select y.col1, y.col2, y.col3
from y
where y.col4 = '*Cash*'
and y.col5 = '*Use*'
and x.someKey = y.someKey)
如果只想更新x
那些在y
UPDATE x
SET (col1, col2, col3) = (select y.col1, y.col2, y.col3
from y
where y.col4 = '*Cash*'
and y.col5 = '*Use*'
and x.someKey = y.someKey)
WHERE EXISTS(select 1
from y
where y.col4 = '*Cash*'
and y.col5 = '*Use*'
and x.someKey = y.someKey)
匹配行的行這些是什麼領域'1','2' ,'3','y.4'和'y.5'?你是指他們的位置,還是這些實際的字段名稱?你打算更新'x'中的每一行還是僅僅匹配一些條件的行? – NullUserException
y.1,y.2,y.3,y.4和y.5是表y中的列。我想用y.1,y.2和y.3中的每個匹配字段來更新x中的每一行,其中y.4與字符串中的現金匹配,y.5與字符串中的使用匹配。 – Deprecated