2008-10-21 104 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的与所需的列,以及填补数据