Ok, I'm back and this is getting a little old. The suggestion that Code Green gave was spot on, but I realized it was still not quite what I need. The code shouldn't be a problem, rather it seems the logic I'm having a problem with.
I need to create a report that lets the user know which of their clients have been in for an appointment in X amount of INTERVAL. The query I have now basically says, "Select all clients where the appointment date is less than the specified time interval". What I really need is "Select all client where the MAX(appointment date) is less than the specified time interval.
The problem is when I use MAX() inside the where, I get a mysql error. How would I write the query to only look at the max appointment date? My code is below:
Currently the sql looks like this:
- "SELECT * FROM clients_tbl JOIN appt_table USING(client_id) WHERE appt_table.appointment_date < DATE_SUB ( CURDATE(), INTERVAL 1 WEEK );"
Ideally what I need is:
- "SELECT * FROM clients_tbl JOIN appt_table USING(client_id) WHERE MAX(appt_table.appointment_date) < DATE_SUB ( CURDATE(), INTERVAL 1 WEEK );"
If anyone has any ideas, I'm all ears.
Thanks again guys!
Greg