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?
            Asked
            
        
        
            Active
            
        
            Viewed 122 times
        
    0
            
            
        - 
                    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 Answers
1
            
            
        use order by and limit
select a.* from table_name a
order by last_mod_date desc
limit 1
 
    
    
        Zaynul Abadin Tuhin
        
- 31,407
- 5
- 33
- 63
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;

