Solved

Get rid of Duplicate records in MS SQL 2000

Posted on 2006-11-29
2
427 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
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 50 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculate values in an array 18 33
Get Duration of last Status Update 4 29
T-SQL: Nested CASE Statements 4 24
Help Extract Specific in SQL 8 19
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now