Left join returning only certain fields [duplicate]

0

I have the following tables:

tb_agenda

date

tb_patient

patient_id patient_name

tb_medico

Medical_id Medical_name

tb_agendamento

asked by anonymous 27.03.2017 / 23:44

1 answer

0

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:

tb_agenda

: int

date : timestamp

time : time

tb_patient

pop_id : int

: string

tb_medico

Medical_id : int

medical_name : string

tb_agendamento

13.04.2017 / 14:59