简体   繁体   中英

Oracle select last record for a particular id

I have a table in oracle 11g like this:

id   date  
---  ---
1    1-jun
1    2-jun
1    3-jun
2    1-jul
2    2-jul
2    3-jul

I am trying to extract the latest record corresponding to each id. I tried group by, max but I cannot get it to work. What I want is:

   id    date 
   ---   ---
    1    3-jun
    2    3-jul

Try this:

SELECT id, MAX(date)
  FROM <YOUR-TABLE>
 GROUP BY id

试试这个

'SELECT *FROM (SELECT * FROM table ORDER BY date   DESC )tmp GROUP BY Id ';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM