Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL-query for latest date in data base

Tags:

sql

sqlite

mysql

Can You help me construct sql query which pulls out of database the entries which have the latest date.

I tried but come to deadend

SELECT *
FROM Table t,Table t2
WHERE t.date>t2.date

I think i have to use some temporary tables...it is a bit dificult for me

like image 243
Csabi Avatar asked May 04 '26 04:05

Csabi


2 Answers

Retrieve rows ordered by date, descending:

SELECT * FROM table ORDER BY date DESC

Retrieve the 5 rows with the most recent dates:

SELECT * FROM table ORDER BY date DESC LIMIT 5
like image 179
Dan Grossman Avatar answered May 05 '26 17:05

Dan Grossman


Try:

select * from Table where date_column = (select max(date_column) from Table)
like image 29
dogbane Avatar answered May 05 '26 18:05

dogbane