【问题标题】:mysql copy to another only new recordsmysql复制到另一个只有新记录
【发布时间】:2013-06-15 19:30:36
【问题描述】:

我要两张桌子:

语言温度:

sku|postid|fi|en|ru(15000 条记录/包括 200 条 full_products 记录)

完整产品:

sku|postid|fi|en|ru|xx|zzz|aaaa|bbb(200 条记录)

postid 是唯一的,不能相同。

我只需要将新记录从 lang temp 复制到 full_products。怎么可能查询?

【问题讨论】:

    标签: mysql mysqli mysqldump mysql-workbench mysql-error-1064


    【解决方案1】:

    试试

    INSERT INTO full_products (sku,postid,fi,en,ru)
    SELECT sku,postid,fi,en,ru
      FROM lang_temp l
     WHERE NOT EXISTS 
     (
       SELECT 1 
         FROM full_products
        WHERE post_id = l.post_id
          AND sku = l.sku
     )
    

    【讨论】:

    • 在某些查询中插入和选择?
    • @user2421781 没错。阅读INSERT ... SELECT Syntax
    • 而在 phpmtadmin 中它只像 select 一样工作,查询不做任何插入
    • 无论使用什么工具,它的工作原理都是一样的。问题在于不存在子查询的条件。为了做到这一点,您能否发布两个表的示例数据以及执行 desc full_productsdesc lang_temp 的结果
    • 谢谢,现在它可以工作了,但是我怎么做检查 - 如果 full_products.postid 没有数学 lang_temp ,那么删除 rhe full_products 记录
    猜你喜欢
    • 2012-06-26
    • 2017-03-24
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多