I am trying to create a query which returns offers for all rows that belong to a club_id that are within a start_date & end_date, however the query should also return results for any that match the club_id AND the end_date is 0 – any ideas of how to do this?
My current query is below…
SELECT
* ,
UNIX_TIMESTAMP( start_date ) AS start_dateStamp,
UNIX_TIMESTAMP( end_date ) AS end_dateStamp
FROM
(`offers`)
WHERE
UNIX_TIMESTAMP( `start_date` ) <1329308797
AND
UNIX_TIMESTAMP( `end_date` ) >1329308797
AND
`club_id` =23
Please note, that I moved the convertion from unix-timestamp to MySQL-date from the field to the constant – this way it has to be converted only once, and not for all rows. Additionally this way an index can be used.
Edit
With “date zero” not being Unix-Zero but MySQL-Zeor the last line should be
additionally, if the data type of
start_dateandend_dateis notDATETIMEbutDATEyou needinstead of