开发者

Obtain the last Inserted record of a group of same ID's

开发者 https://www.devze.com 2023-02-15 14:36 出处:网络
So, i have this structure: IDSaleDateInserted 120开发者_开发知识库11-1-12 12011-1-13 12011-1-10 22011-1-12

So, i have this structure:

IDSale    DateInserted  
1          20开发者_开发知识库11-1-12
1          2011-1-13
1          2011-1-10
2          2011-1-12
2          2011-1-15
2          2011-1-11

The result of my question would be:

IDSale    DateInserted  
1          2011-1-13
2          2011-1-15

How can I achieve this in a MYSQL Query. I can do this programatically, but


Well, for this particular case, the following will do the trick:

SELECT IDSale, MAX(DateInserted) DateInserted
FROM tablename
GROUP BY IDSale
0

精彩评论

暂无评论...
验证码 换一张
取 消