Solved

How to remove duplicate records from two different tables

Posted on 2008-09-29
3
300 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 200 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

839 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