I have the following tables:
tb_agenda
date
tb_patient
patient_id patient_name
tb_medico
Medical_id Medical_name
tb_agendamento
I have the following tables:
date
patient_id patient_name
Medical_id Medical_name
It would be something like this:
SELECT id_agendamento, hora, nome_medico, nome_paciente FROM tb_agenda AS agenda
INNER JOIN tb_agendamento AS agendamento ON agenda.id_agenda = agendamento.id_agenda
INNER JOIN tb_paciente AS paciente ON paciente.id_paciente = agendamento.id_paciente
INNER JOIN tb_medico AS medico ON medico.id_medico = agenda.id_medico
See more about making a relationship here
There are still some additions to the structure of your tables. It depends on which business rule you want to implement, but in most cases it would look better:
: int
date : timestamp
time : time
pop_id : int
: string
Medical_id : int
medical_name : string