如何在没有任何重复的情况下从一个表插入另一个表? [英] How Do I Insert From One Table To Another Without Any Duplicate ?

查看:77
本文介绍了如何在没有任何重复的情况下从一个表插入另一个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tabel1



tabel1

name   date       amount  phoneno   addresss chequeno bank 
   abc      10/09/2014 100000  145278    ncbdh    h2634    BSH
   bcjd     09/05/2014 52222   9822014   nhdhdd   A103    ING


table2 
name      date        amount     phoneno    address   chequeno    bank  remark    statement 
 bcjd     09/05/2014  52222      9822014    nhdhdd    A103        ING   cleared   payment done





这一行在table2中不可用

所以这一行应该插入:



this row is not available in table2
so this row should insert :

abc    10/09/2014 100000  145278    ncbdh    h2634    BSH



,表2中没有。



如果它已经可用,那么没有变化。

否则插入。


which is not available in table2

if it is already available then no change for that .
otherwise insert .

推荐答案

你好,

我不知道你的桌子结构。

但是根据你的要求你可以试试这段代码



Hello ,
I don't know your table structure .
but according to your requirement you can try this code

insert into table2
select * from table1 where  table1.name not in (select name from table2)





这里我根据名称在table1中插入table2中的数据。最好是有任何独特或主键如Id(Auto int)



希望它可以帮到你。



谢谢



here i insert data in table2 from table1 on the basis of name . It is better if there is any unique or primary key like Id(Auto int)

hope it helps you.

thanks








检查这个...







Hi,


Check this...



insert into table2 t2
select * from table1 t1 
where t2.name <> t1.name 
and t2.date <> t1.date
and t2.amount <> t1.amount
and t2.chequeno <> t1.chequeno





以上我正在考虑减少可能提供记录唯一性的列。



希望这会对你有所帮助。





干杯。



above i am considering less possible columns which may provide uniqueness of record.

Hope this will help you.


Cheers.


试试这个



Try this

INSERT INTO Table2
SELECT *
FROM  Table1 T1
      LEFT OUTER JOIN Table1 T2 ON T1.NAME = T2.NAME
WHERE T2.Name is null


这篇关于如何在没有任何重复的情况下从一个表插入另一个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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