Answers for "mysql last date"

SQL
1

mysql last date

-- Max date for each model:
SELECT model, max(date) FROM models GROUP BY model;
-- All models matching the max date of the entire table:
SELECT model, date FROM models WHERE date IN (SELECT max(date) FROM models);
-- Same with model details:
SELECT d.model, d.date, d.color, d.etc FROM models d
WHERE d.date IN (SELECT max(d2.date) FROM models d2 WHERE d2.model=d.model);
-- Faster with MySQL 8.0+
SELECT model, date, color, etc FROM (SELECT model, date, color, etc, 
  max(date) OVER (PARTITION BY model) max_date FROM models) predoc 
WHERE date=max_date;
Posted by: Guest on June-13-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language