There are tables:
Tickets (designed to issue a voucher to the doctor at the hospital) it consists of the following fields:
- IdTicket
- DoctorKod (doctor code from the Doctors table)
- RegistrationKod (registration code from the Registration table)
- DateReception (reception date)
Registration (intended for registration of the patient in the hospital), it consists of the following fields:
- IdRegistration
- DateRegistration
- ParticientKod (patient code from the Patients table)
Patients:
- IdParticient
- Fio
- Address
- CityKod
How can I get data from the Tickets table, but so that the patient's FIO is displayed from the Patients table, i.e. You need to display in the ticket the name of the patient who made an appointment with the doctor.
I tried to do through the inner join
, but not very. In general, there is an idea to simply add a patient code to the Registration table, but if there is an opportunity to get around this, it would be cool.
Below I have attached the sql in which I do all this, but instead of the full name of the patient, I’ll enter the date of his registration (from the Registration table).
SELECT Doctors.IdDoctor, Doctors.FIO, Registrations.IdRegistration, Registrations.DateRegistration, Tickets.DateReception FROM ( ( Tickets INNER JOIN Doctors ON Tickets.DoctorKod = Doctors.IdDoctor ) inner join Registrations on Tickets.RegistrationKod = Registrations.IdRegistration )