I have a php script that allows a user to generate reports, they have the option of selecting 3 date ranges.
i.e.
2012-01-01 to 2012-01-31
AND
2011-01-01 to 2011-01-31
AND
2010-01-01 to 2010-01-31
But when I do my query, and there are no records between a certain date range, the query returns no values.
Here is my query:
SELECT DealerName WHERE InterviewDate >= "2012/01/01 " AND InterviewDate <= " 2012/03/31"
AND InterviewDate >= "2012/07/01 " AND InterviewDate <= " 2012/09/31"
I need a query that will return data if it is found in 1 of the date ranges, regardless of whether there is no data in the subsequent date ranges.
The data is summarized into a table where it would be possible for a the same data to be on multiple dates.
for example:
dealerName 1 2012-01-01
dealerName 1 2012-02-31
dealerName 2 2012-03-01
dealerName 1 2012-06-01
dealerName 1 2012-06-31
So If I wanted to query the data between 2012-01-01 and 2012-02-31 AND 2012-06-01 AND 2012-06-31. I realise that 1 date range could encompass all of these ranges, but the user may want to exclude data between these two date ranges.
A interview date can not be between x and y AND still be between z and zz. You are missing a
OR– Also, have a look at theBETWEENoperatoredit, sorry, missed the table name 🙂