如何将一行项目复制到另一行

时间:2013-02-05 21:23:57

标签: sql sql-server-2008

我有以下表格:

Student_ID  Description 
1       0x
2       0x1G800....
3       0x1F800....

Student_ID 1为空值如何使用sql查询将student_ID 2的值复制为1。

1 个答案:

答案 0 :(得分:2)

这就是你要找的全部吗?

Update Student
SET Description = (SELECT Description FROM Student WHERE Student_ID = 2)
WHERE Student_ID = 1

或使用JOIN

UPDATE S 
SET S.Description = S2.Description
FROM Student S JOIN
    Student S2 ON S2.Student_ID = 2
WHERE S.Student_Id = 1
祝你好运。