MySQL help required for writing a query
I have number of records in database of which some are duplicates like
1 test 20-09-2011
2 main 20-09-2011
3 New 20-09-2011
4 test 20-09-2011
5 test 20-09-2011
6 test 20-09-2011
7 main 20-09-2011
8 main 20-09-2011
Now what i want is i g开发者_JAVA百科et all three distinct records but with maximum id record out of them as below:
3 New 20-09-2011
6 test 20-09-2011
8 main 20-09-2011
Please suggest
Thanks all
select *
from table as t1
where t1.id = (select max(t2.id) from table as t2 where t1.name =t2.name)
where name is the second attribute of your table.
精彩评论