-2

I am using SQL server.Import data from Excel . i have Following Fields column

 Entity ExpenseTypeCode Amount  Description APSupplierID    ExpenseReportID 
   12     001            5       Dinner      7171                  90
   12     001            6       Dinner      7171                  90
   12     001            5       Dinner      7273                  90
   12     001            5       Dinner      7171                  95
   12     001            5       Dinner      7171                  90

I added Sample Data. Now I want select Duplicate Records .which Rows have all columns value same i want fetch that row. suppose above My table Fifth Row duplicate . i have more four thousands Query . i want select Duplicate records .Above I mention . please How to select using Query ?

Nitin Kumar
  • 878
  • 6
  • 22
thenna
  • 413
  • 1
  • 5
  • 24

1 Answers1

1

If you want the values that are duplicated, then use group by:

select Entity, ExpenseTypeCode, Amount, Description, APSupplierID,     ExpenseReportID, count(*) as numDuplicates
from t
group by Entity, ExpenseTypeCode, Amount, Description, APSupplierID,     ExpenseReportID 
having count(*) > 1;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709