General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
>>I am trying to get a list of the next appointment for a group of people. I can easily get a list of all future appointments for these people. To narrow it down to 1 row per person I used the GROUP BY clause. However, which record does the data come from when using GROUP BY. In other words: A person may have 10 appointments, but I have a single record for each person with a date. I don't know how it decides which of the 10 dates to display. Is it the first record, last record, random record?
>>
>>TIA,
>>Marcus.
>
>Do something like...
>
>Select PersonID,Min(AppoinmentDate) From Appointments Where AppointmentDate >= DATE() Group By PersonID
>
>This will give you each person with the lowest date which meets the where condition, which above is today or later. Said another way, this will give you a list of everyones next appointment.
>
>BOb
Thanks Bob,
I swear I tried this and it only returned one record with the smallest date for the entire group of people. I must have tried it without the GROUP BY clause, because it works beautifully now. Thanks, that is exactly what I was looking to do.
Marcus.
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only