Solved

Display ALL Duplicate records in Table

Posted on 2007-11-28
2
236 Views
Last Modified: 2010-04-21
I am currently using the HAVING method to select duplicate records as follows:

SELECT MachineName, COUNT(*) AS 'Duplicate Count' FROM [NICresults]
GROUP BY MachineName
HAVING ( COUNT(*) > 1 )

which produces these results:

MachineName | Duplicate Count
Machine01 | 2
Machine06 | 3
Machine34 | 2

So far so good, but what I need to do now is display all the records and not just what is duplicated.  I have a table with all my machines and the NICs installed in each.  Some Machines have a single NIC and some have multiple NICs.  I need a list of machines with multiple NICs and the actual records which include the NIC details for each.

I am thinking there must be a way to compare the results of the first SELECT to create a SELECT that pulls only the records that have those results.  but again I am unsure how to do it.

any help would be greatly appreciated
0
Comment
Question by:reinsmms
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 20363885
this should do
SELECT t.*, d.[Duplicate Count]
FROM [NICresults] t
JOIN (
   SELECT MachineName, COUNT(*) AS [Duplicate Count] FROM [NICresults]
  GROUP BY MachineName
   HAVING ( COUNT(*) > 1 
    ) d
ON d.MachineName = t.MachineName

Open in new window

0
 

Author Closing Comment

by:reinsmms
ID: 31411368
Perfect! thanks a billion!
I believe I basically understand how this works.  The first part of the select statement is creating two results "t.*" (all records) and field to hold the the count "d.[Duplicate Count]" is the JOIN statement what is populating that field?  and how does the ON statement work? Would you be willing to give me a short explaination or point me to a good resource?  
In any case this keeps me moving, MUCH APPRECIATED!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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