仅当特定情况有效时,我才需要更新特定列。但是,以下内容正在更新我表中的所有内容。我正在嵌套表格本身,因为我必须自行更新表格。
更新所有内容的 Query1:
UPDATE TestTable m
SET m.column1 = 'VALUE2' -- I don't need any nested column data, I specifically know the data needs to UPDATE from 'Value1' to 'Value2' for filtered rows from nested Query
WHERE EXISTS
(
SELECT 1
FROM TestTable m1
WHERE
m1.column2='xyz'
AND (
m1.nameColumn IN ('%ME%','%MYSELF%') --- This is not really used, I am just saying I have additional filters.
)
AND ( m1.column1 = 'VALUE1' OR m1.column1 IS NULL ) -- We need to update the records which have 'VALUE1' column1 only..
)
查询2:也一样......
UPDATE TestTable m
SET m.column1
= (
select 'VALUE2' -- Like example1, I don't need the nested table's data at all.
-- I need the nested query to filter out rows to let the outer query know that only those rows are to be updated
FROM TestTable m1
WHERE
m1.column2='xyz'
AND (
m1.nameColumn IN ('%ME%','%MYSELF%') --- This is not really used, I am just saying I have additional filters.
)
AND ( m1.column1 = 'VALUE1' OR m1.column1 IS NULL ) -- We need to update the records which have 'VALUE1' column1 only..
)
--WHERE m1.column1 != m.column1 --- THIS DOESN'T WORK, this is an added check that I don't update where it is not needed. It can be removed/ignored