Solved

Display ALL Duplicate records in Table

Posted on 2007-11-28
2
245 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 143

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 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