I have posted this over at the MySQL forum with no responses, so I thought I might pick the brains of the PHP gurus... I'm having an issue with an SQL query. Heres what I have:
2 tables, client_tbl and appt_table, they join using client_id
I'm trying to write a report that will show me:
a) Any clients that have not had an appointment in X amount of time.
This would be done using DATE_SUB(CURDAT E(), INTERVAL $time $units) and comparing that against the appointment date in the appt_table.
b) Any clients that have not ever been scheduled for an appointment.
This would be done by finding clients that have no records in the appointment table.
I'm hoping this can be done in one query, but I'm thinking it's not possible. What I have now works only if a client has previously been scheduled (so part a above works), but if a client has never been scheduled, they are not included in the query results.
Any idea how I can select something if it's NOT in another table?
My current SQL is below:
The obvious thing here is that if a client hasn't ever been scheduled there is no appt_date_time in the database so the where fails and the client isn't included in the result. This is where i need help!
Again, I apologize for the double post, but I wasn't getting any takers in the other forum. Mods, please feel free to edit / remove this post if I'm showing bad form.. :)
Greg
2 tables, client_tbl and appt_table, they join using client_id
I'm trying to write a report that will show me:
a) Any clients that have not had an appointment in X amount of time.
This would be done using DATE_SUB(CURDAT E(), INTERVAL $time $units) and comparing that against the appointment date in the appt_table.
b) Any clients that have not ever been scheduled for an appointment.
This would be done by finding clients that have no records in the appointment table.
I'm hoping this can be done in one query, but I'm thinking it's not possible. What I have now works only if a client has previously been scheduled (so part a above works), but if a client has never been scheduled, they are not included in the query results.
Any idea how I can select something if it's NOT in another table?
My current SQL is below:
Code:
SELECT * FROM client_tbl LEFT JOIN appt_table USING (client_id) WHERE appt_table.appt_date_time < DATE_SUB( CURDATE(), INTERVAL 2 week)
Again, I apologize for the double post, but I wasn't getting any takers in the other forum. Mods, please feel free to edit / remove this post if I'm showing bad form.. :)
Greg
Comment