Here is the RECORDS
MySQL TABLE:
ID - BIGINT(20)
DATE - DATE
Records:
ID Date
1 2014-03-01
2 2014-03-02
3 2014-04-01
4 2014-04-02
Here is the first Query:
SELECT id, DATE_FORMAT(date,'%d/%m/%Y') AS date FROM records
WHERE
date >= STR_TO_DATE('01/04/2014','%d/%m/%Y') AND
date <= STR_TO_DATE('30/04/2014','%d/%m/%Y')
Everything is OKAY, I get the result:
3,2014-04-01
4,2014-04-02
But, when I try to get the date range with a subquery like this:
SELECT *
FROM (SELECT id, DATE_FORMAT(date,'%d/%m/%Y') AS date
FROM records) AS TEST
WHERE
date >= STR_TO_DATE('01/04/2014','%d/%m/%Y') AND
date <= STR_TO_DATE('30/04/2014','%d/%m/%Y')
I get an empty result set (i.e. zero rows).
Where is my mistake?