PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > Extracting Duplicates from SQL Server 2000
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Extracting Duplicates from SQL Server 2000

Réponse
 
LinkBack Outils de la discussion
Vieux 28/12/2007, 19h13   #1
apatel85@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Extracting Duplicates from SQL Server 2000

Hey Guys,

Total Number of Records (Based on 5 fields): 1000
Total Unique Records (Based on 5 Fields): 990
Total number of fields: 5

I have question regarding extracting duplicates from the dataset. I
have 2 fields that makes a record unique. I have used group by
function to find duplicates and got 10 records that are duplicating.
Each records duplicating 1 times, thus, 10 unique records and 10
duplicates, giving me 990 unique records out of 1000.

Now, I want to filter out duplicates from the dataset and get unique
records, including all 5 fields. Here is the query that I used.

select *
from (
select field1, field2, count(*)
from table 1
group by field 1, field2
having count(*) >1
)a,
table 1 b
where a.field1=b.field1 and a.field2=b.field2

When I use this query, it gives me duplicate records as i am matching
on both fields that makes records unique. Is there anyway to just
extract unique records?

Thank you very much for your .

--AP
  Réponse avec citation
Vieux 28/12/2007, 19h35   #2
Roy Harvey (SQL Server MVP)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Extracting Duplicates from SQL Server 2000

On Fri, 28 Dec 2007 10:13:43 -0800 (PST), apatel85@gmail.com wrote:

>Now, I want to filter out duplicates from the dataset and get unique
>records, including all 5 fields.


I'm not at all clear what you are trying for, but perhaps adding
DISTINCT to your query will do it.

Roy Harvey
Beacon Falls, CT
  Réponse avec citation
Vieux 28/12/2007, 23h07   #3
Hugo Kornelis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Extracting Duplicates from SQL Server 2000

On Fri, 28 Dec 2007 10:13:43 -0800 (PST), apatel85@gmail.com wrote:

>Now, I want to filter out duplicates from the dataset and get unique
>records, including all 5 fields. Here is the query that I used.

(snip)

Hi AP,

Your problem is not clear to me. I suggest that you post your table
structure (as a CREATE TABLE statement, including constraints,
properties and indexes), a few well-chosen rows of sample data (as
INSERT statements) to illustrate the problem, and the output required
from that sample data. See www.aspfaq.com/5006 for more details.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
  Réponse avec citation
Vieux 28/12/2007, 23h49   #4
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Extracting Duplicates from SQL Server 2000

(apatel85@gmail.com) writes:
> Now, I want to filter out duplicates from the dataset and get unique
> records, including all 5 fields. Here is the query that I used.
>
> select *
> from (
> select field1, field2, count(*)
> from table 1
> group by field 1, field2
> having count(*) >1
> )a,
> table 1 b
> where a.field1=b.field1 and a.field2=b.field2
>
> When I use this query, it gives me duplicate records as i am matching
> on both fields that makes records unique. Is there anyway to just
> extract unique records?
>


Could this do?

SELECT a.*
FROM tbl a
WHERE EXISTS (SELECT *
FROM (SELECT field1, field2
FROM tbl
GROUP BY field, field2
HAVING COUNT(*) > 1) AS b
WHERE a.field1 = b.field1
AND a.field2 = b.fiedl2)


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
  Réponse avec citation
Vieux 09/01/2008, 21h07   #5
Knowledgy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Extracting Duplicates from SQL Server 2000

Please post example DDL. It seems like a insert...select distinct query
would get your results if all columns for each duped row is exactly the same

--
Sincerely,
John K
Knowledgy Consulting, LLC
knowledgy.org

Atlanta's Business Intelligence and Data Warehouse Experts


<apatel85@gmail.com> wrote in message
news:960e924b-2856-4c60-82fe-b04707c42990@e6g2000prf.googlegroups.com...
> Hey Guys,
>
> Total Number of Records (Based on 5 fields): 1000
> Total Unique Records (Based on 5 Fields): 990
> Total number of fields: 5
>
> I have question regarding extracting duplicates from the dataset. I
> have 2 fields that makes a record unique. I have used group by
> function to find duplicates and got 10 records that are duplicating.
> Each records duplicating 1 times, thus, 10 unique records and 10
> duplicates, giving me 990 unique records out of 1000.
>
> Now, I want to filter out duplicates from the dataset and get unique
> records, including all 5 fields. Here is the query that I used.
>
> select *
> from (
> select field1, field2, count(*)
> from table 1
> group by field 1, field2
> having count(*) >1
> )a,
> table 1 b
> where a.field1=b.field1 and a.field2=b.field2
>
> When I use this query, it gives me duplicate records as i am matching
> on both fields that makes records unique. Is there anyway to just
> extract unique records?
>
> Thank you very much for your .
>
> --AP



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11993 seconds with 13 queries