如何更新?

时间:2013-01-14 14:55:19

标签: mysql sql

我有这个:

   ID      ROW_A    ROW_B

'62919' | '9430' | '40754'

感谢这个问题:

SELECT * FROM myTable 
WHERE ROW_A != 0

我想更新它,将ROW_A的值放入ROW_B

那么,是否可以通过一个查询进行以下处理?

现在,我正在使用它(但这是错误的):

UPDATE myTable SET ROW_B = ROW_A
WHERE ID IN(
SELECT * FROM myTable
WHERE ROW_A != 0)

3 个答案:

答案 0 :(得分:5)

我认为不需要子查询:

UPDATE  myTable 
SET     ROW_B = ROW_A
WHERE   ROW_A != 0

答案 1 :(得分:2)

UPDATE myTable 
SET ROW_B = ROW_A
WHERE ROW_A != 0

答案 2 :(得分:0)

这可能有效:

UPDATE myTable SET ROW_B = A
WHERE ID IN(
SELECT ROW_A as A FROM myTable
WHERE ROW_A !=0)