SQL插入 去除重覆記錄的實現

2021-08-20 22:14:48 字數 689 閱讀 8157

最近的在做乙個cs的專案後端使用了oracle資料庫,功能實現的過程中要求對sql語句進行很好的處理,這就涉及到了今天的主題sql插入時去除重覆記錄的實現,這裡有兩種方式提供給大家分別是 merge into,not exists。

下面將通過兩種方式來實現: 將 表a 與 表b 不重複的user資訊 插入表b

merge

into

table a

using

table b

on (a.user_id = b.user_id)

when

notmatched

then

insert

values (b.user_id, b.user_name, b.user_***);

insert

into

table (id,name,***)

select id,name,***

from

table a

where user_id = ' uid '

andnot

exists

( select * from

table b where a.mi_no=b.mi_no )

只是乙個sql的小應用,還在不斷的學習中,榮幸與您分享~

SQL去除某欄位重覆記錄

sql去除某欄位重覆記錄 原理 對需要去重覆記錄的字段按組排序,然後取其中一條記錄。在總查詢語句中使用in語法過濾 去掉重覆記錄 select from company where comid in select max comid from company group by companyname...

SQL去除某欄位重覆記錄

原理 對需要去重覆記錄的字段按組排序,然後取其中一條記錄。在總查詢語句中使用in語法過濾 去掉重覆記錄 select from company where comid in select max comid from company group by companyname 得到重覆記錄數 sele...

SQL去除某欄位重覆記錄

原理 對需要去重覆記錄的字段按組排序,然後取其中一條記錄。在總查詢語句中使用in語法過濾 去掉重覆記錄 select from company where comid in select max comid from company group by companyname 得到重覆記錄數 sele...