0

我试图将行从表复制到另一个仅使用 2 列,因为拖表模式不相同,我收到此错误

操作数应包含 1 列

任何提示我的陈述有什么问题?

 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)
                )
4

5 回答 5

2

尝试将 where 条件从 更改(T2.screenname = T1.screenname,T2.list_id = T1.list_id)(T2.screenname = T1.screenname AND T2.list_id = T1.list_id)

(注意 AND 关键字而不是逗号)

于 2012-07-31T11:28:21.747 回答
1

您是否尝试过 INSERT INTO...ON DUPLICATE KEY 语法?

在此处查看 MySQL 手册

于 2012-07-31T11:27:47.477 回答
1

您可以在 table1 中的 screenname 和 list_id 列上创建唯一索引然后使用以下语句

将忽略插入 table1 ( screenname,list_id ) Select screenname,list_id From table2 As T1

于 2012-07-31T11:30:18.193 回答
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;
于 2012-07-31T11:37:11.983 回答
0

使用简单的 INSERT IGNORE

INSERT table1 (screenname, list_id) SELECT screenname, list_id FROM table2
于 2018-07-02T09:12:51.853 回答