Need SQL Help

ryan256

Platinum Member
Jul 22, 2005
2,514
0
71
I have a table that I need to find duplicate entries for based on 3 values. If 2 or more rows contain the same values for col_A, col_B, and col_C then they are duplicates.

I was able to do this when the duplicates were determined by a single column using:
SELECT col_A, COUNT(col_A) AS Expr1
FROM Table_1
GROUP BY col_A
HAVING (COUNT(col_A) > 1)
ORDER BY Expr1 DESC

This told me how many duplicates I had of column A. I then used:

SELECT distinct col_A
INTO Table_1_temp
FROM Table_1

This gave me a table free of duplicates.

But I'm lost on how to do this now that there are 3 variables in the mix.
I'm thinking that to get a table free of duplicates based on 3 variables I would use:

SELECT distinct col_A, col_B, col_C
INTO Table_1_temp
FROM Table_1

But again I'm shooting in the dark here as I have very little SQL experience.
 

GeekDrew

Diamond Member
Jun 7, 2000
9,099
19
81
SQL questions generally belong in the Programming forum, for what it's worth.

Originally posted by: ryan256
I'm thinking that to get a table free of duplicates based on 3 variables I would use:

SELECT distinct col_A, col_B, col_C
INTO Table_1_temp
FROM Table_1

But again I'm shooting in the dark here as I have very little SQL experience.

Yes, from what you've told us, that will give you what you're looking for. If you use SELECT DISTINCT rather than just SELECT, you're essentially telling the server to not return any rows that have identical data to any row that it has already returned.