代码之家  ›  专栏  ›  技术社区  ›  OscarRyz

从两个数据库中删除重复的记录

  •  1
  • OscarRyz  · 技术社区  · 15 年前

    我设法从两个不同的数据库中识别重复的记录:

    select * from 
        taskperformance a,  taskperformance@dm_prod b
    where 
        a.activityin = b.activityin
        and a.completiondate = b.completiondate
    

    如何删除重复记录 b ?

    我试过:

    delete taskperformance@dm_prod  where exist ( 
    select * from 
        taskperformance a,  taskperformance@dm_prod b
    where 
        a.activityin = b.activityin
        and a.completiondate = b.completiondate ) 
    

    但它删除的内容比我需要的要多。

    1 回复  |  直到 11 年前
        1
  •  2
  •   Sam Chad    11 年前

    你不应该引用 b 在子查询中:

    delete taskperformance@dm_prod b
    where exists (
        select * from taskperformance a
        where a.activityin = b.activityin 
        and a.completiondate = b.completiondate 
    )