tags:

views:

63

answers:

1

I manage to identify duplicate records from two different databases:

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

How can I delete duplicated records from b?

I tried:

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

But delete more that I need.

+2  A: 

Yeah - you shouldn't re-reference b in the subquery:

delete taskperformance@dm_prod b
where exists (
    select * from taskperformance a
    where a.activityin = b.activityin 
    and a.completiondate = b.completiondate 
)
Rob Farley
Oops I'm sorry. Bad editing. I didn't re-reference b. It is a typo. I dod it like you posted and it delete all the records. .. :( Thank god I put autocommit to false... ( didn't I? :-o )
OscarRyz
I believe you can still use aliases... delete t@db2 alias where...
Greg Ogle
@Greg Ogle: Could you expand that comment a bit. Suppose I don't know what your are talking about ;)
OscarRyz
He's mentioning that I removed the alias of 'b' - that's probably a MSSQL v Oracle thing... but I'm not talking about the alias in my answer, I'm talking about the fact that you mention the table again in the FROM clause of the subquery. In my answer, I only mention taskperformance in the FROM clause of the subquery, not taskperformance@dm_prod
Rob Farley
Ohh oh I see... I'll try that ...
OscarRyz
It says the db link does not exists: ( like the field was part of the db link name ) : Error: ORA-04054: database link DM_PROD.COMPLETIONDATE does not exist
OscarRyz
But using an alias did the job!!! Great! Thanks a million Rob:
OscarRyz
Ah, yup. Cool. In SQL Server you can't use an alias in quite that way, so I'm always in the habit of using the tablename if I use this construct. Great that you got it sorted. :)
Rob Farley