selecting distinct

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Can someone please tell me how I can do this:

I have an appointment table which has appointment_id, client_id,
appoinment_time (as unix timestamp). Clients can have multiple

I want to select all appointments from the appointment table but only
one appointment (the latest one) for clients that have multiple
appointments. How do I do this?

Re: selecting distinct

foo wrote:
Quoted text here. Click to load it

This correlated subquery can do it:

FROM appointment AS a
WHERE a.appointment_time =
   (SELECT MAX(a2.appointment_time)
    FROM appointment AS a2
    WHERE a2.client_id = a.client_id)

Bill K.

Site Timeline