Hello SQL Gurus,
I am trying to form a MySQL query (version 4.1) that will return all of the clients and their most recent certificate info from the certificates table, by using max(exp_date) which is the date that their certificate expires. It is a one to many relationship, as each client can have may certificates, but I only want to see the info of the one with the latest exp_date.
I have tried several different forms of the query with only partial success. I believe that it will probably require a sub-query but I have not been able to get it formed properly. I have not written many sub-queries and have not been able to get it right.
Here is my latest attempt not using a sub-query that unfortunately also does not work. It pulls all of the records, and the certificate info, but it does not get the certificate with the latest exp_date.
SELECT
certs.exp_date,
certs.cert_no,
clients.client_id,
clients.state_lic,
clients.o_fname,
clients.o_lname,
clients.bus_name
FROM comm_certs certs
Inner Join comm_clients clients ON certs.client_id = clients.client_id
GROUP BY certs.client_id
HAVING MAX(certs.exp_date)
ORDER BY clients.client_id ASC
Any assistance would be very much appreciated.
Thank you,
Marc McIntire