Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to remove duplicate records from two different tables

Posted on 2008-09-29
3
Medium Priority
?
310 Views
Last Modified: 2012-06-27
HI everybody,

I have two database tables

Animal1
ID                  Type               Name
1                    cat                   felix
2                    dog                   ruff
3                    dog                   rover
4                    dog                   skip
5                    cat                    heathcliff

Animal2
ID                 type                   Name
1                  cat                     felix
4                   dog                   skip
3                  horse                   ED

Now if i have duplicate records in both tables I need to delete the duplicates from the "animal2" table. How can i do that?  Is there a way to write a query to do this?
0
Comment
Question by:RegWood79
3 Comments
 
LVL 15

Accepted Solution

by:
jorge_toriz earned 800 total points
ID: 22601963
DELETE Animal2
WHERE ID IN (SELECT ID FROM Animal1)
0
 
LVL 5

Expert Comment

by:ursangel
ID: 22602985
delete from Animal2 where type in
(select type from animal1
group by type)
0
 

Author Closing Comment

by:RegWood79
ID: 31501418
thanks jorge that's exactly what I was looking for.  
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question