paniwe courf
paniwe courf

Reputation: 43

How to select newest records

How would I get the most recent records from a MySQL database?

My table looks like this:

NAME   AGE  COUNTRY   CREATED 

JEMO  23    UK        2019-04-25 17:41:29
JET   27    USA       2019-05-05 18:21:20
KET   20    CA        2019-05-06 19:16:12

MySQL Query:

SELECT * FROM USER WHERE TIMESTAMP(CREATED) = NOW() 

I want to select users who just created an account, like the most recently registered or newest users. How would I do this?

Upvotes: 2

Views: 35

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

In mysql you could select the user with the most recent date CREATED this way

 select *
 FROM  USER 
 order by CREATED DESC
 limit 1 

OR select the matching date for max created

select *
FROM  USER 
WHERE CREATED  = (
  select  max(CREATED) FROM USER 
)

Upvotes: 1

Related Questions