Share via

Need SQL Query for unique constraint 2 columns take all Min date except Max Date

Indudhar Gowda 426 Reputation points
2022-06-02T05:21:26.397+00:00

Need SQL Query for unique constraint 2 columns take all Min date and do not take Max Date.

207720-image.png

In the Above Screen Shot.....Need SQL Query for [reportableresultcode] and [iscalculated] are unique constraint 2 columns, Take duplicates but dont take MAX Date.

Insert Duplicate Row's in TempTable.

I have attached the Excel sheet ..

Azure SQL Database
SQL Server Reporting Services
SQL Server Reporting Services

A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Answer accepted by question author

Jingyang Li 5,901 Reputation points Volunteer Moderator
2022-06-02T15:38:13.73+00:00
SELECT 
[reportableresultid]
      ,[samplecode]
      ,[testprepetitioncode]
      ,[testcode]
      ,[parametercode]
      ,[reportableresultcode]
      ,[iscalculated]
      ,[createdonutc]
FROM (SELECT   [reportableresultid]
      ,[samplecode]
      ,[testprepetitioncode]
      ,[testcode]
      ,[parametercode]
      ,[reportableresultcode]
      ,[iscalculated]
      ,[createdonutc]
      ,row_number() Over(partition by reportableresultcode,  iscalculated  order by [createdonutc] desc) rn
  FROM  [dbo].[yourtablename]
  ) t
  where rn>1

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.