2012-07-31 167 views
0

我試着從表中複製一行到另一個使用2 coluom只拖表架構是不相同的, 正在此錯誤複製行從一個表到另一個,忽略重複

操作數應包含1列( s)

任何提示最新錯誤與我的聲明?

Insert table1 (screenname,list_id) 
    Select screenname,list_id 
From table2 As T1 
Where Not Exists (
       Select 1 
       From table1 As T2 
       Where 
       (T2.screenname = T1.screenname,T2.list_id = T1.list_id) 
       ) 

回答

2

嘗試改變where條件從(T2.screenname = T1.screenname,T2.list_id = T1.list_id)(T2.screenname = T1.screenname AND T2.list_id = T1.list_id)

(注和關鍵字,而不是逗號)

+0

正確:)看起來像它,而不是逗號,謝謝你的提示:) – LeoSam 2012-07-31 11:31:33

1

你試過INSERT INTO ... ON DUPLICATE KEY語法嗎?

見MySQL手冊here

1

可以在表1創建唯一索引的列屏幕名和list_id 然後使用以下語句

將忽略插入表1(屏幕名,LIST_ID) 選擇屏幕名,LIST_ID 從表2爲T1

0

也可以嘗試這個查詢 -

INSERT INTO table1 (screenname, list_id) 
    SELECT screenname, list_id FROM table2 t2 
    LEFT JOIN table1 t1 
     ON t1.screenname = t2.screenname AND t1.list_id = t2.list_id 
    WHERE 
    t1.screenname IS NULL AND t1.list_id IS NULL; 
相關問題