2011-02-25 24 views
2

我想知道是否有可能做一个INSERT语句与已经存在的记录。例如:
INSERT语句与现有的记录

insert into tbl(item_name, item_price) values(select item_name, item_price from tbl where id = 5) 

说的id是自动递增的PK。

当我尝试类似这样的东西,我得到错误:

Msg 156, Level 15, State 1, Line 1 
Incorrect syntax near the keyword 'select'. 
Msg 102, Level 15, State 1, Line 1 
Incorrect syntax near ')'. 

我失去了一些东西,或者是这是不可能的?

+0

标题编辑... – 2011-02-25 00:28:33

回答

5

结帐这篇文章:Adding Rows by Using INSERT and SELECT

但无论如何,正确的方法是:

insert into tbl(item_name, item_price) 
select item_name, item_price 
    from tbl 
where id = 5 
+0

啊,我是不是太离谱.. THX :) – 2011-02-25 00:40:10

3

试试这个:

insert into tbl(item_name, item_price) select item_name, item_price from tbl where id = 5 
+0

ROTFL ..我已经为正确答案:) – 2011-02-25 00:34:51

+0

HAHAH,粗糙的人群的人得到downvote。 +1 – 2011-02-25 00:39:44