我有两个表:Set1和SearchInfo。它们看起来像这样:
Set1
SearchID | Position
3 1
1 7
3 4
SearchInfo
SearchID | SearchDate
1 6
2 8
3 9
我想将Searchdate列添加到Set1并使用SearchID作为键。这就是我的尝试:
ALTER TABLE Set1 ADD COLUMN SearchDate1 DATETIME;
INSERT INTO Set1 (SearchDate1) SELECT b.SearchDate FROM Set1 a
LEFT OUTER JOIN SearchInfo b ON a.SearchID=b.SearchID;
但是,这就是我得到的
Set1
SearchID | Position | SearchDate1
3 1
1 7
3 4
x
x
x
反对:
Set1
SearchID | Position | SearchDate1
3 1 9
1 7 6
3 4 9
答案 0 :(得分:0)
您想要的是:这将更新您已经完成的列。你不需要插入任何东西
Update SET1
Set SearchDate = si.SearchDate
From Set1 s
inner join SearchInfo si
where s.SearchID = si.SearchID