Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have a Table Like This:

____________________________________________________________________
******ID******post_title_code******post_eff_date******site****empno
____________________________________________________________________
******01********1011************01/10/1999*******1070*****123
******02********1011************01/10/2000*******1070*****123
******03********1011************01/10/2001*******1070*****123
******04********1012************01/10/2002*******1070*****123
******05********1000************01/10/2003*******1070*****123
******06********1000************01/10/2000*******1070*****123

Now i have different ID's but the post_title_codes are same in various places..Now i want the resultant to display the record but the post_title_code should be distinct and in that it should display the record with highest ID..
E.G the output of the above mentioned Table should be like"
____________________________________________________________________
******ID******post_title_code******post_eff_date******site****empno
____________________________________________________________________
******03********1011************01/10/2001*******1070*****123
******04********1012************01/10/2002*******1070*****123
******06********1000************01/10/2000*******1070*****123

Here in this output we can see that the post_title_codes are distinct and the from them only that record is displayed which had the MAXIMUM ID..
like in post_title_code for '1011' had three records so it displayed the one with the highest ID among these three records..

Any help would be highly appreciated..
Thank You..
Posted

select max(ID), post_title_code from tblWhatever group by post_title_code
 
Share this answer
 
Thanks Mr. Christian.

It was creating duplicates coz i had a need of all the columns..
As when i select all the columns it asked me to use them in Group By Clause but that i managed to rectify that..
Thanks a lot and the credit is still urs..
 
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