如果在sql的新表中不存在该条目,如何将行从一个表复制到另一个表 [英] How to copy row from a table to another table if the entry is not exist in the new table in sql

查看:44
本文介绍了如果在sql的新表中不存在该条目,如何将行从一个表复制到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将所有数据从一个表复制到另一个相同的模式表.如果新表已经有一行,那么我不需要更新或插入它.我只需要新表中不存在的旧表中的新数据即可复制到该新表中.

I need to copy all data from a table to an another same schema table. If the new table has a row already then i need not to update or insert it. I need only new data from old table that does not exist in new table to copy to that new table.

那么什么是sql查询,有谁可以帮助我.

So what will be the sql query, can any one help me.

谢谢,蒙塔西尔·拉赫曼·拉菲

Thanks, Muntasir Rahman Rafi

推荐答案

尝试一下:

INSERT INTO TABLENAME2 (col1, Col2, col3)
SELECT *
FROM tablename1 A
WHERE NOT EXISTS (
          SELECT *
          FROM tablename2 B
          WHERE A.col1 = B.col1
     )

这篇关于如果在sql的新表中不存在该条目,如何将行从一个表复制到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆