This query suppose to find all duplicates in the vContractDetails table. At the moment it is taking forever to process. Can any one spot any problems? Or help to optimise it? Thanks in advance
*********************************************
SELECT DISTINCTROW vContractDetails.Start, vContractDetails.End, vContractDetails.Project, tStaff.FirstName, tStaff.LastName, vCompany.name, vContractDetails.[Daily Rate], vContractDetails.[Hours per day], vContractDetails.[Hourly Rate], vContractDetails.StaffId
FROM (tStaff RIGHT JOIN vContractDetails ON tStaff.StaffId = vContractDetails.StaffId) LEFT JOIN vCompany ON vContractDetails.[Company Ref] = vCompany.[Account Number]
WHERE (((vContractDetails.StaffId) In (SELECT [StaffId] FROM [vContractDetails] As Tmp GROUP BY [StaffId],[Start],[End] HAVING Count(*)>1 And [Start] = [vContractDetails].[Start] And [End] = [vContractDetails].[End])))
ORDER BY vContractDetails.Start, vContractDetails.End;
******************************************
*********************************************
SELECT DISTINCTROW vContractDetails.Start, vContractDetails.End, vContractDetails.Project, tStaff.FirstName, tStaff.LastName, vCompany.name, vContractDetails.[Daily Rate], vContractDetails.[Hours per day], vContractDetails.[Hourly Rate], vContractDetails.StaffId
FROM (tStaff RIGHT JOIN vContractDetails ON tStaff.StaffId = vContractDetails.StaffId) LEFT JOIN vCompany ON vContractDetails.[Company Ref] = vCompany.[Account Number]
WHERE (((vContractDetails.StaffId) In (SELECT [StaffId] FROM [vContractDetails] As Tmp GROUP BY [StaffId],[Start],[End] HAVING Count(*)>1 And [Start] = [vContractDetails].[Start] And [End] = [vContractDetails].[End])))
ORDER BY vContractDetails.Start, vContractDetails.End;
******************************************