
October 11th, 2004, 10:45 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by ronmegga I am trying to create a query in MySQL with PHP. I have 2 tables , client_info and activity. The user will input 2 dates creating a range(to and from). I am trying to get the most recent activity.next_appt_date for a client, compare it to the date range and if a client's most recent activity.next_appt_date is with in the range given, then return that client's info as well at the activity.next_appt_date. i cant seem to get the query to work correctly, here is what I have so far...
$appt_sql = "SELECT a.ssn,MAX(a.date_next_appt),c.fname,c.lname,c.ssn FROM activity as a INNER JOIN client_info as c ON a.ssn=c.ssn WHERE (MAX(a.date_next_appt) > '$date_from' AND MAX(a.date_next_appt) < '$date_to') GROUP BY c.fname,c.lname,c.ssn";
the reason I need the most recent date being with in the date range is that there may be several entries for a client and there may be a more recent entry for that client so if they have a activity.next_appt_date with in the range but isnt that client's most recent, I dont want that client returned. This may be simple but I am not very familiar with complex MySql queries. Any help would be greatly appreciated. |
Thanks for all of your "No Help". i figured it out on my own...here is the solution..
$appt_sql = "SELECT a.ssn, MAX(a.date_next_appt) as apptdate, c.fname, c.lname FROM activity AS a INNER JOIN client_info AS c ON a.ssn = c.ssn GROUP BY a.ssn, c.fname, c.lname HAVING MAX(a.date_next_appt) BETWEEN '$date_from' AND '$date_to'";
|