Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Duplicated Records

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
0
0
CA
I have a table with two columns. The first column contains the ID and second one contains the number. I'm trying to find the duplicated records (numbers) and display the numbers with the IDs.

Data
Code:
ID       NUMBER
D4999    BIN9003
D3955    BIN9003
D5666    BIN9003
B2022    BIN0007

Output
Code:
NUMBER     ID1     ID2     ID3
BIN9003    D4999   D3955   D5666

Current query
Code:
SELECT NUMBER, COUNT(ID) AS Dupes
FROM TABLE
GROUP BY NUMBER
HAVING (COUNT(ID)>1);

I'm obviously only getting the duplicated numbers with the number of times it's duplicated with the query above.

 
The "find duplicates query wizard" will come up will the same output because it's about the same query as mine. So I only get one ID and not all the IDs sharing the same number.

 
This
Code:
SELECT t1.ID, t1.Num
FROM TABLE t1
WHERE t1.Num IN [COLOR=red](SELECT t2.Num
FROM TABLE t2
GROUP BY t2.Num
HAVING (((Count(t2.ID))>1))[/color]);
will return:
ID Num
D4999 BIN9003
D3995 BIN9003
D5666 BIN9003
You can probably turn it into a crosstab query without too much trouble.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top