Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
** Main table structure


ComplainId Name PhNo CreatedDate Status
PAC000010 Raja 9876543456 2016-01-14 18:05:04.703 FollowUp1
PAC000016 Raja 9876543456 2016-01-14 19:29:36.530 FollowUp1
PAC000016 Raja 9876543456 2016-01-15 11:10:07.170 FollowUp2
PAC000016 Raja 9876543456 2016-01-14 18:32:53.123 Closed
PAC000019 Raja 9876543456 2016-01-15 11:13:17.747 FollowUp1


**I need the following table structure

ComplainId Name PhNo CreatedDate Status
PAC000019 Raja 9876543456 2016-01-15 11:13:17.747 FollowUp1
PAC000016 Raja 9876543456 2016-01-14 18:32:53.123 Closed
PAC000010 Raja 9876543456 2016-01-14 18:05:04.703 FollowUp1
Posted

1 solution

Well it's pretty simple! Try this


SQL
SELECT *
FROM   
(
    SELECT ComplainId, MIN(CreatedDate) MIN_DATE
    FROM   MAIN_TABLE
    GROUP BY ComplainId
) T INNER JOIN MAIN_TABLE M ON T.ComplainId = M.ComplainId AND T.MIN_DATE = M.CreatedDate
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900