MySQL check if dates in db include the dates of given date range
I'm new to MySQL. Can anyone help me with this.
I got two dates say From_Date = '2012-04-01'
, To_Date = '2012-04-17'
. I want to get all the details from the table that contains the date within the given date.
Name Subject Start_Date End_Date
Madhu Science 2011-05-01 2012-05-01
Madhu Biology 2012-04-01 2012-04-07
Mahesh 开发者_如何学GoScience 2011-05-01 2012-05-01
Jagadesh Biology 2011-05-01 2012-03-01
My answer should contain:
Madhu Science
Madhu Biology
Mahesh Science
select * from table_name
where start_date >= "2012-04-01"
and end_date <= "2012-04-17"
You can also use BETWEEN statement part.
See mySQL Reference # Between
精彩评论