mysql max date

Solutions on MaxInterview for mysql max date by the best coders in the world

showing results for - "mysql max date"
Sophie
01 Oct 2018
1-- Max date for each model:
2SELECT model, max(date) FROM models GROUP BY model;
3-- All models matching the max date of the entire table:
4SELECT model, date FROM models WHERE date IN (SELECT max(date) FROM models);
5-- Same with model details:
6SELECT d.model, d.date, d.color, d.etc FROM models d
7WHERE d.date IN (SELECT max(d2.date) FROM models d2 WHERE d2.model=d.model);
8-- Faster with MySQL 8.0+
9SELECT model, date, color, etc FROM (SELECT model, date, color, etc, 
10  max(date) OVER (PARTITION BY model) max_date FROM models) predoc 
11WHERE date=max_date;