简体   繁体   English

将数据从表A复制到表B时出错

[英]Error in copying data from table A to table B

I am facing an error 我遇到错误

ERROR 1062 (23000): Duplicate entry '42322-xyz@yahoo.co.in' for key 'PRIMARY'

while copying data from one table to another. 同时将数据从一个表复制到另一个表。 is it possible to by-pass rows from table A which are in table B, I am trying to use 是否可以绕过表B中的表A中的行,我正在尝试使用

INSERT INTO tableB SELECT * FROM tableA as A join v2_opens as B on A.id!=B.id and A.emailid != B.emailid WHERE  A.date='2015-01-27';

but for above query i am getting an error: 但是对于上面的查询,我得到一个错误:

ERROR 1136 (21S01): Column count doesn't match value count at row 1

Would request you to suggest and help me how to overcome these issue. 请您提出建议并帮助我如何克服这些问题。 My concern is to copy data from TableA to TableB, if there comes any duplicate entry(with primary key) than it must be by-passed. 我担心的是将数据从TableA复制到TableB,如果有任何重复的条目(带有主键),并且必须绕过它。

For bypassing rows, I prefer on duplicate key update . 对于绕行,我更喜欢on duplicate key update This prevents exactly that error. 这恰好防止了该错误。

When doing an insert, you should generally include the columns you want to insert: 进行插入时,通常应包括要插入的列:

INSERT INTO tableB(col1, . . .)
    SELECT col1, . . .
    FROM tableA as A join
         v2_opens as B on A.id <> B.id and A.emailid <> B.emailid
    WHERE  A.date='2015-01-27'
    ON DUPLICATE KEY UPDATE col1 = values(col1);

However, I would be surprised if this query were really want you wanted to do. 但是,如果此查询确实要您执行,我会感到惊讶。 This may be sufficient: 这可能就足够了:

INSERT INTO tableB(col1, . . .)
    SELECT col1, . . .
    FROM tableA a
    WHERE  A.date = '2015-01-27'
    ON DUPLICATE KEY UPDATE col1 = values(col1);

Or perhaps this: 也许这样:

INSERT INTO tableB(col1, . . .)
    SELECT col1, . . .
    FROM tableA as A LEFT JOIN
         v2_opens as B
         ON A.id = B.id and A.emailid = B.emailid
    WHERE A.date = '2015-01-27' AND B.id IS NULL;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将表从服务器 A 复制到服务器 B - Copying table from Server A to server B 将数据从一个表复制到另一个表的 sql 查询中的语法错误 - Syntax error in sql query of copying data from one table to another 如何通过在MySQL中将数据从colum abc复制到colum d来更新表 - how to update table by copying data from colum a b c to colum d in MySQL 从表中检索数据,其中它们是3个表A,B,C。 而表C的折射率在B中,表的B折射率在A中 - Retriving data from table, where their are 3 table A,B,C . And refrence of Table C is in B, Table's B refrence is in A 从多个表中复制数据并插入其中一个? - copying data from multiple table and insert into one? MySQL-将数据从一个表复制到另一个表 - MySQL - Copying data from one table to another 输入数据从“ A”表中获取数据,然后与“ B”表中的数据进行核对,然后在数据不在“ B”表中时显示数据 - input data bring data from 'A' table then check with 'B' table with the data then show the data when the data not in 'B' table 复制关系表数据 - Copying Relational Table Data 从表中复制行到另一个表时出错 - Getting error from copying row from table to another table 将数据从一个数据库表复制到不同服务器上的另一表 - Copying data from one database table to another table on different servers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM