Answers for "mysql last date of month"

SQL
4

mysql get last day of month

SELECT LAST_DAY(CURDATE());						-- Current month
SELECT LAST_DAY(CURDATE() - INTERVAL 1 MONTH);	-- Previous month
SELECT LAST_DAY(CURDATE() + INTERVAL 1 MONTH);	-- Next month
Posted by: Guest on May-21-2021
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 "mysql last date of month"

Code answers related to "SQL"

Browse Popular Code Answers by Language