【问题标题】:Copying data if it does not exist如果数据不存在则复制数据
【发布时间】:2012-04-30 10:19:15
【问题描述】:

我有一个包含许多表的数据库。一个表有 2 列数据,第 1 列包含“电子邮件地址”,第 2 列包含“newsletterscubscriber”,值为 1。

我有另一个表(最终表)具有相同的列,该表已经填充了数据。我想让数据库读取(最终表)然后检查第一个表是否有任何差异。然后,我希望它在包含两列数据的最终表格中添加任何差异。顺便说一句,这实际上来自 oscommerce 数据库。

【问题讨论】:

    标签: mysql-management


    【解决方案1】:
    SELECT `table1`.`col1tbl1`, `table1`.`col2tbl1`, `table2`.`col1tbl2`, `table2`.`col2tbl2` FROM `table1`, `table2` WHERE `col1tbl1` != `col1tbl2` AND `col2tbl1` != `col2tbl2`
    
    table1 = final table
    table2 = first table
    col1tbl1 = name of first column for table1
    col2tlb1 = name of second column for table1
    col1tbl2 = name of first column for table2
    col2tbl2 = name of second column for table2
    

    上面的 SQL 会将 table1 中的 2 列与 table2 中的 2 列进行比较。如果没有匹配,它应该显示 table1 中所有不匹配的记录。然后,您可以获取该数据,将其保存到数组中并使用递归脚本将数据插入到 table2 中。

    注意:我整理了表格,因为您没有提及任何内容。另外,我显然无法测试它,但请尝试一下。

    【讨论】:

      猜你喜欢
      • 2021-06-25
      • 1970-01-01
      • 2021-12-10
      • 2017-04-24
      • 2016-11-19
      • 2023-04-04
      • 2019-11-17
      • 2018-09-22
      • 1970-01-01
      相关资源
      最近更新 更多