I am downloading data from a 3rd party datasource and one field is a contact’s birthday, which may be blank i.e. 0000-00-00. My users have the option of entering the contact’s birthday if they choose, and I hold this is in a separate table because if I updated the original table, whenever the user refreshed with the original datasource, all updated birthdays would be erased.
I now want to find all birthdays in next 30 days. This works on the first (original datasource) table:
$BirthdayResults = mysql_query("SELECT * FROM Connections WHERE UserID='$UserID' AND (DATE_FORMAT(ContactBirthday, '%m%d') BETWEEN '$sCurrentDate' AND '$sDateOneMonthAdded')");
So I am wondering if mySQL can handle this type of logic:
$BirthdayResults = mysql_query("SELECT * FROM Connections WHERE UserID='$UserID'...
AND IF ContactBirthday IN Connections = '0000-00-00'
CHECK OTHER_BIRTHDAY_TABLE AND USE THIS BIRTHDAY IF IT EXISTS
WHERE Connections.ContactID=OTHER_BIRTHDAY_TABLE.ContactID
However,
NULLwould be more appropriate than0000-00-00in this situation; in which case one could use MySQL’sIFNULL()orCOALESCE()functions instead: