Get ... WHERE MAX(column) .... using a LEFT JOIN
Posted: Sun Feb 22, 2009 6:56 am
I have been using a left join to get some data from a MySQL table using PHP without problems, but now the 'service_take' column will have more than one entry. The table has a 'serviced_date' column which has the date entered as a date stamp (e.g. 1226882280).
I just want to return the last entry and have tried using my altered join as follows:
and as
but get 'Invalid use of group function' errors, anyone any idea where I am going wrong here?
Thanks in advance
I just want to return the last entry and have tried using my altered join as follows:
Code: Select all
$the_qry = ("SELECT tl.tl_id, tl.tl_name, tl.tl_contact, tl.tl_town, st.st_counter_end, st.st_split "
. "FROM table_locations AS tl LEFT JOIN service_take AS st ON (tl.tl_id = st.st_tl_id) WHERE MAX(st.st_serviced_date)");Code: Select all
$the_qry = ("SELECT tl.tl_id, tl.tl_name, tl.tl_contact, tl.tl_town, st.st_counter_end, st.st_split "
. "FROM table_locations AS tl LEFT JOIN service_take AS st ON (tl.tl_id = st.st_tl_id) WHERE st.st_serviced_date = MAX(st.st_serviced_date)");Thanks in advance