Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL get mindate and maxdate in one query

How to get the maxmum date and minimum date in mysql using only one sql query?

like image 312
Timo Huovinen Avatar asked Jan 04 '12 13:01

Timo Huovinen


People also ask

How can find max and min date in SQL?

The SQL MIN() and MAX() FunctionsThe MIN() function returns the smallest value of the selected column. The MAX() function returns the largest value of the selected column.

How can I get specific records in MySQL?

MySQL SELECT statement is used to retrieve rows from one or more tables. The statement can also include UNION statements and subqueries. SELECT statement is used to fetch rows or records from one or more tables.

Is between and inclusive in MySQL?

The MySQL BETWEEN operator is inclusive. For example, when you use the MySQL BETWEEN operator to retrieve the books whose price is in the range between 50 and 90, the result retrieves all of these books, including those whose price equals 50 or 90.

How do I find the smallest date in MySQL?

How do I find the smallest date in MySQL? MySQL MIN() Function The MIN() function returns the minimum value in a set of values.


2 Answers

SELECT MIN(date_col), MAX(date_col) FROM table_name 
like image 68
Icarus Avatar answered Oct 19 '22 05:10

Icarus


JUST IN CASE someone came here looking for minimum and maximum supported dates like I did... here's the answer to your question :)

select      DATE('1000-01-01') MinDate,      DATE('9999-12-31') MaxDate  +------------+------------+ | MinDate    | MaxDate    | +------------+------------+ | 1000-01-01 | 9999-12-31 | +------------+------------+ 

Reference: https://dev.mysql.com/doc/refman/5.5/en/datetime.html

like image 36
Joseph Nields Avatar answered Oct 19 '22 03:10

Joseph Nields