Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get rid of Duplicate records in MS SQL 2000

Posted on 2006-11-29
2
Medium Priority
?
434 Views
Last Modified: 2011-09-20
Table R
Category   Classes  Brand      Model      
AAA          BBB       CCC        DDD
BBB          CCC       DDD        EEE
CCC         AAA       BBB         ZZZ
CCC         AAA       BBB         EEE

Table A
Category   Classes  Brand      Model      
AAA          BBB       CCC        AAA
BBB          CCC       DDD        FFF
CCC         AAA       BBB         ZZZ (* - already exist in table R)
CCC         AAA       CCC        ZZZ

I need to insert data in Table A into Table B, but don't want the duplicate record (see *) as Table R is a reference table and no duplicate records in allowed.  How to prevent Table R from having duplicate records after the insertion?

Please advice.

Thank you.
0
Comment
Question by:woo_kh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 200 total points
ID: 18043360
INSERT INTO R
SELECT *
FROM A a1
WHERE NOT EXISTS (SELECT 1 FROM R WHERE Category = A1.Category and Classes = A1.Classes and Brand = A1.Brand AND Model = A1.Model)
0
 
LVL 17

Expert Comment

by:HuyBD
ID: 18043373
insert into tableA
select * from tableB B
left join tableR R on R.Category=B.Category and R.Brand=B.Brand and R.Model=B.Model
where R.Category is null
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

715 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