Solved

Display ALL Duplicate records in Table

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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.​
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…
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…

914 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

16 Experts available now in Live!

Get 1:1 Help Now