Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Display ALL Duplicate records in Table

Posted on 2007-11-28
2
Medium Priority
?
264 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 1000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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