I have this four tables:
One for users, other for professionals, other for patients y another for appointments. I want to get the name of professional from patient's appointment.
I try this:
SELECT appointments.date, appointments.start_time, appointments.indication, professionals.medical_box
FROM appointments
INNER JOIN patients ON appointments.id_patient = patients.id
INNER JOIN users ON users.id = patients.id_user
INNER JOIN professionals ON professionals.id = appointments.id_professional
WHERE users.id = 14
ORDER BY appointments.date DESC, appointments.start_time ASC
And I get all correctly, but when I try to show users.name, the name that I get is the patient name, no the professional name, I want the professional name from that patient appoinment. What will be the sql query?