Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table with the following fields


ID Name Message
1 aaa Hi
2 sss Hello
3 mmm Gud
4 aaa Hello
5 bbb Hi
6 sss seeYou
7 aaa Ok
8 bbb Ok


ID is the PrimaryKey and Name is a foreignKey

I need a query to see only the last updates of each user
That is I need a result like

ID Name Message
3 mmm Gud
5 sss seeYou
6 aaa Ok
7 bbb Ok



Can anyone please help me..?
Thanks in advance
Posted
Updated 7-Jul-15 3:05am
v2

1 solution

There are many ways but something like this may help-
SQL
SELECT T1.ID, T1.Name, T1.Message
FROM YourTable AS T1
INNER JOIN
(
  SELECT MAX(ID),Name
  FROM YourTable
  GROUP BY Name
) AS T2
ON T1.ID=T2.ID


Hope, it helps :)
 
Share this answer
 
Comments
Baiju christadima 7-Jul-15 11:13am    
Thanks..
Suvendu Shekhar Giri 7-Jul-15 11:40am    
Glad to know that it helped :)

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