0

denter image description here

This is the table what looks like. I want to select only the record that Last Modified Date is Max. EX: Will Only select 2nd record in above Table. Is it possible?

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
banura96
  • 71
  • 5
  • This seems the same as your question. Take a look here https://stackoverflow.com/questions/2411559/how-do-i-query-sql-for-a-latest-record-date-for-each-user – Mukul Kumar Jul 23 '21 at 08:30

2 Answers2

1

use order by and limit

select a.* from table_name a
order by last_mod_date desc
limit 1
Zaynul Abadin Tuhin
  • 30,345
  • 5
  • 25
  • 56
1

If you only want a single row even if the max value appears more than once, use LIMIT:

select amount, created_date, last_mod_date
from the_table
order by last_mod_date desc
limit 1;

If you want multiple rows if the max value appears more than once, you can use a window function:

select amount, created_date, last_mod_date
from (
    select amount, created_date, last_mod_date, 
           dense_rank() over (order by last_mod_date desc) as rn
    from the_table
) t 
where rn = 1;
a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843