Forum Moderators: coopster
i am doing the following query
SELECT * FROM request, response, advt
WHERE request.request_id = response.request_id
AND advt.ad_uid = response.ad_uid
AND request.date BETWEEN '$from_date' AND '$to_date'
but if aug date and sept date are compare then we can have the result..
why it is so..?
AND request.date BETWEEN '$from_date' AND '$to_date'
By enclosing your dates in single quotes you are implying you are using date-strings? But (I'm guessing) if your request.date is also a string then it's going to perform a string comparison, not a date comparison? If request.date is a DATE type then you might need to CAST() your date-strings to DATE ?
BETWEEN will probably require the use of the MySQL CAST() function, to properly compare the two dates. It's been a while since I've used BETWEEN, but I imagine it would be something like this:
SELECT * FROM request, response, advt
WHERE request.request_id = response.request_id
AND advt.ad_uid = response.ad_uid
AND request.date BETWEEN CAST('$from_date', date) AND CAST('$to_date', date)
Also note, if you use CAST(), and you have some dates as datetimes and others as just dates, you'll need to use CAST() to cast the offending date to the right type i.e. - datetime or date