Home > database >  Return only one record (most recent) from a large data set
Return only one record (most recent) from a large data set

Time:03-30

I want to pull the most recent removed date as one line item. The below query lists all the names. However, in the output I just want one line item that shows the name with most recent removed date. How do I go about doing this?

select table1.name, table1.removed_date
from table1
where table1.status = 'Removed' and table1.removed_date is not null
order by table1.removed_date desc

CodePudding user response:

Just add limit 1 at the end of your query. Yes, that is the answer.

CodePudding user response:

Well, I have a question. How do we make sure it's the absolutely most recent removed date if multiple rows with the same removed_date exist? Should we add a timestamp column to further narrow down the choices ? Or is there another way to find out the most recently updated row ?

  • Related