I have two date columns, domain_renew_date and hosting_renew_date.
I am trying to show the rows which need to be renewed in the next x days.
But if i order by one column then the other, some dates which are close to the current date will be ignored because the other column doesn’t need renewing.
Is it possible to compare two columns for the largest value and use that value to order by?
This is what i have at the moment, but i have just found out ‘greatest’ doesn’t do what im trying to make it do.
"SELECT *
FROM `domains` as Domain
WHERE (`domain_renew_date` < '".$date."' AND `domain_renew_date` != '0000-00-00')
OR (`hosting_renew_date` < '".$date."' AND `hosting_renew_date` != '0000-00-00')
ORDER BY greatest(`domain_renew_date`, `hosting_renew_date`) ASC"
Thanks.
Or even more simple
SELECT if(domain_renew_date > hosting_renew_date, domain_renew_date, hosting_renew_date) as greater_date
FROM
domainsWHERE hosting_renew_date >= '".date."' OR domain_renew_date >= '".$date."'
ORDER BY greater_date ASC