SQL Help [message #370567] |
Thu, 23 December 1999 15:07 |
marcus
Messages: 9 Registered: July 1999
|
Junior Member |
|
|
I am trying to select the most recent date using sql. I have several patients that have several appointment dates, but I only want to see the most recent. Anyone got any advice. I know it's probably easy, but for whatever reason I have no clue. Thanks.
|
|
|
Re: SQL Help [message #370569 is a reply to message #370567] |
Thu, 23 December 1999 20:49 |
Paul
Messages: 164 Registered: April 1999
|
Senior Member |
|
|
Marcus,
If all you want is to return 2 columns, a name and a date, you can
SELECT patient_name, MAX(appointment_date)
FROM your_table
GROUP BY patient_name;
If you need to return more columns than this (for example, if patient names are stored in FNAME and LNAME columns), you can use something like this:
SELECT fname, lname, appointment_date
from your_table t1
WHERE date = ( SELECT MAX(appointment_date)
FROM your_table t2
WHERE t2.fname = t1.fname
AND t2.lname = t1.lname );
Hope this helps,
Paul
|
|
|
|