2008-10-21 33 views

回答

5

這是你在找什麼?

INSERT INTO MyTable 
SELECT * FROM AnotherTable 
WHERE AnotherTable.ID < 5 
+0

太好了。 正如其他人所提到的,您需要確保從AnotherTable中選擇的列與MyTable中的列匹配。 – 2008-10-21 19:52:53

3

該語法看起來正確,但您的字段必須完全匹配,否則將無法正常工作。

您可以指定字段,例如:

INSERT INTO myTable(COL1, COL2, COL3) 
SELECT COL1, COL2, COL3 FROM anotherTable where anotherTable.id < 5 
0

Insert Into MyTable ( Col1, Col2, Col3 ) Select Col1, Col2, Col3 From AnotherTable Where ID < 5

0

你也可以做

select * 
into MyTable 
from AnotherTable 
where ID < 5 

,這將創造MyTable的與所需的列,以及填補數據