Skip to content
Advertisement

How to delete duplicate rows in a table based on what is supposed to be a unique column referring to a table in another database

In Table A PersonID refers to Table B another database and is supposed to be unique here. For reasons, it isn’t and a stored procedure that uses PersonID and FacilityID as input parameters is returning multiple rows for the instances of that duplicate PersonID. I would like to remove the top record in Table A as it does not belong by comparing it to what the PersonID is supposed to be.

I thought about comparing the PersonID and DOB here against Table B and remove records that didn’t match, however, I haven’t been able to come up with the way to do it.

Advertisement

Answer

I understand that you want to delete records for which no corresponding record exists in the other table with the same PersonId and DateOfBirth.

If so, you can use an anti-left join as follows:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement