[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

Display Duplicate Records SQL

Hi

I am generating a query to show records that are duplicate.  But I need to add in an extra field, FSCode, when I add this in I get nothing returned, but I know there are records that are duplicated for this.
Any help would be great.
Thanks
SELECT  FCode,  NAVDate, NAVTime,
 COUNT(NAVTime) AS NumOccurrences
FROM tblclassnav
GROUP BY FCode,  NAVDate, NAVTime
HAVING ( COUNT(*) > 1 )
and navtime >= '1899-12-30 23:59:59.000'

Open in new window

0
ITHELPME
Asked:
ITHELPME
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
i think it is because, there exists no duplicate records with the same "  FCode,  NAVDate, NAVTime, FSCode " 
0
 
RiteshShahCommented:
yes, I agree, there may be duplicate records for FSCODE but not duplicate for  FCode,  NAVDate, NAVTime, FSCode

0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Hope this helps you out:

Note : This will work in SQL Server 2005 and above and not in SQL Server 2000.
Revert if you are using SQL Server 2000.
SELECT FCode,  NAVDate, NAVTime
FROM (
SELECT  FCode,  NAVDate, NAVTime,
ROW_NUMBER() OVER ( PARTITION BY NAVDate, NAVTime ORDER BY NAVDate, NAVTime) rnum
FROM tblclassnav
WHERE navtime >= '1899-12-30 23:59:59.000' ) temp
WHERE rnum > 1

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ITHELPMEAuthor Commented:
I am using SQL 200, it does not recognise ROW_NUMBER

For the answer above there are duplicate records for FCode, FSCode, NAVDate, NAVTime
0
 
RiteshShahCommented:
are you running this and don't get results?

SELECT  FSCODE,FCode,  NAVDate, NAVTime,
 COUNT(NAVTime) AS NumOccurrences
FROM tblclassnav
GROUP BY FSCODE,FCode,  NAVDate, NAVTime
HAVING ( COUNT(NAVTime) > 1 )
and navtime >= '1899-12-30 23:59:59.000'
0
 
ITHELPMEAuthor Commented:
When I run the above I get nothing returned, but when I take out FSCode I get results

I do have dupliacte records for these on NAVTime as NAVTime is a different Time but all others are the same

0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
If it is SQL Server 2000 then try this one out:
SELECT  t1.FCode,  t1.NAVDate, t1.NAVTime
FROM tblclassnav t1, (
SELECT  NAVDate, NAVTime,
 COUNT(NAVTime) AS NumOccurrences
FROM tblclassnav
GROUP BY NAVDate, NAVTime
HAVING ( COUNT(*) > 1 )
and navtime >= '1899-12-30 23:59:59.000') t2
where t1.NAVDate = t2.NAVDate
and t1.NAVTime = t2.NAVTime

Open in new window

0
 
ITHELPMEAuthor Commented:
it does sort of

Sometimes I will have more than one record for FCode, NAVDate, NAVTime

But I should not have more than one record for FCode, FSCode, NAVDate, NAVTime i this makes sense
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
ITHELPME,
     Kindly explain your comment more so that I can help you out.
Have you tried my query in comment no 24327546
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now