Consider I have 4 columns in a table and i have datas for 3 columns like below
考虑我在表中有4列,我有3列的数据,如下所示
TableTest
Col1 | Col2 | Col3
D11 | D12 |
D21 | D22 |
Normally the update query would be
通常更新查询将是
Update TableTest SET Col1 = D11 , Col2 = D12 , COL3 = newdata Where Col1= D11
The Scenario is , the update query should only push data to the COL3 , it should skip the Col1 and Col2, as it has already filled with data(even if same or different data for the Col1 and Col2)
方案是,更新查询应该只将数据推送到COL3,它应该跳过Col1和Col2,因为它已经填充了数据(即使Col1和Col2的数据相同或不同)
5 个解决方案
#1
11
This might help -
这可能有所帮助 -
UPDATE TableTest a
INNER JOIN TableTest b ON a.Col1 = b.Col1
SET a.Col3 = 'newData'
WHERE a.Col3 IS NULL
An INNER JOIN
with the same table so that it updates the appropriate row!
INNER JOIN具有相同的表,以便更新相应的行!
#2
6
If you just want to update COL3 than don't include other columns in UPDATE query.
如果您只想更新COL3而不是在UPDATE查询中包含其他列。
Query:
Update TableTest SET COL3 = newdata Where Col1= D11
#3
4
You should update whole table using single query as:
您应该使用单个查询更新整个表:
Update TableSet SET COL3=CONCAT('D',CONVERT(Substr(Col2,2),INT)+1)
This will update table as follows:
这将更新表如下:
TableTest
Col1 | Col2 | Col3
D11 | D12 | D13
D21 | D22 | D23
#4
3
Just do it, like this:
就这样做,就像这样:
Update TableTest SET COL3 = newdata Where Col1= D11
#5
2
In UPDATE query, there is no need to reassign the value of col1 and col2 if those values are not changing.
在UPDATE查询中,如果这些值没有更改,则无需重新分配col1和col2的值。
UPDATE TableTest
SET COL3 = newdata
WHERE Col1= 'D11';
#1
11
This might help -
这可能有所帮助 -
UPDATE TableTest a
INNER JOIN TableTest b ON a.Col1 = b.Col1
SET a.Col3 = 'newData'
WHERE a.Col3 IS NULL
An INNER JOIN
with the same table so that it updates the appropriate row!
INNER JOIN具有相同的表,以便更新相应的行!
#2
6
If you just want to update COL3 than don't include other columns in UPDATE query.
如果您只想更新COL3而不是在UPDATE查询中包含其他列。
Query:
Update TableTest SET COL3 = newdata Where Col1= D11
#3
4
You should update whole table using single query as:
您应该使用单个查询更新整个表:
Update TableSet SET COL3=CONCAT('D',CONVERT(Substr(Col2,2),INT)+1)
This will update table as follows:
这将更新表如下:
TableTest
Col1 | Col2 | Col3
D11 | D12 | D13
D21 | D22 | D23
#4
3
Just do it, like this:
就这样做,就像这样:
Update TableTest SET COL3 = newdata Where Col1= D11
#5
2
In UPDATE query, there is no need to reassign the value of col1 and col2 if those values are not changing.
在UPDATE查询中,如果这些值没有更改,则无需重新分配col1和col2的值。
UPDATE TableTest
SET COL3 = newdata
WHERE Col1= 'D11';