I'm try to use the result of a subquery in the query's WHERE clause. The attribute I am wishing to use is last_contact. See below.
SELECT forename, surname, type,
( SELECT MAX(completed_date)
FROM tblTasks
WHERE prospect_id = tblProspects.prospect_id AND completed = '1'
) AS last_contact,
created_at
FROM tblProspects
WHERE hidden != '1' AND type='Prospect' AND last_contact > DATE_ADD(CURDATE(), INTERVAL -90 DAY)
ORDER BY last_contact ASC
I get the SQL Error: #1054 - Unknown column 'last_contact' in 'where clause'
Any help would be greatly appreciated.
Thanks.