2016-08-04 72 views
0

我需要一些幫助,我的SQL代碼:插入選擇自動遞增錯誤

insert into '.$type.' select * from ' .$type.' where effective_id = '.$id

,但我得到的錯誤與此代碼。

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3' for key 'PRIMARY' (SQL: insert into actionplan select * from actionplan where effective_id = 3) 

任何想法如何跳過id列?我必須在幾個表上使用這個代碼。所以我不能寫所有的專欄。

+1

什麼DBMS?這個變化與特定SQ L產品。 – RBarryYoung

+1

根據錯誤消息添加了'mysql'標記 –

回答

1

你基本上問「我怎麼使用select *,但不排除其中一列?`

對不起,這不是select *手段。這意味着獲得所有列,沒有語法SQL爲select *-except-for-id

如果你想除了一個所有列,那麼您必須拼寫出所有你想要的列。

$sql = "insert into $type (id, col1, col2, col3) 
    select NULL, col1, col2, col3 from $type where effective_id = $id";