In a previous Post, I was doing a very simple database with 3 tables "doctor", "patient" and "visit". I've tried to make it more realistic and included now a many to many relationship between "doctor" and "patient". "visit" is the table resulting in this n-m relation. I assume the following simple structure for my table : 

```

doctor
- idDoctor
- name

patient
-idPatient
-name
-dob

visit
-idVisit
-idPatient
-idDoctor
-timestamp

```

I'm using the following data on which I want to make a query :

```

idVisit  idDoctor  idPatient  timestamp
1        1         1          2010-07-19 14:10
2        1         2          2010-07-19 15:10
3        2         1          2010-07-19 15:10
4        3         1          2010-07-19 16:10
5        2         2          2010-07-19 18:10
6        2         3          2010-07-19 19:10
7        1         1          2010-07-19 20:10

```

I have then 3 patients and 3 doctors. For example, the patient 1 went two times to see doctor 1, one time doctor 2 and one time doctor 3.

I would like to build my request so that for each couple (doctor, patient) i have the last visit. This query should return the id Visits (2,3,4,5,6, 7) and not 1 because the last visit that the patient paid to the doctor 1 was at 20:10 and not 14:10. How could I do that ?

I really appreciate you comments and your help. It really helps me to improve my designs as I begin using SQL.