sql not fetching the date range

user7978382

Here is the below query

 SELECT * FROM music_history WHERE date1 BETWEEN 2017-06-24 AND 2017-06-01

when is run this query in phpmyadmin it says MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0011 sec ) even though i have date available from to that range in database.

Here is the database image

database image

Gordon Linoff

In a BETWEEN query, the two operands are ordered. So, this should do what you want:

WHERE date1 BETWEEN '2017-06-01' AND '2017-06-24' 

I assume the lack of single quotes was just a typo.

I would encourage you to write the query using binary comparisons, in this fashion:

WHERE date1 >= '2017-06-01' AND date1 < '2017-06-25' 

This works even when date1 has a time component.

You might find this blog interesting. Although it is about SQL Server, it really applies to any database:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive