Retrieve data from SQL tables [closed]

0

I am developing an application for the management of shifts of a medical office, when I register a new shift I keep the id of it (autoincremental) and I keep a id of the patient, one of the doctor, and one of the state of the shift.

But when I retrieve the data to show it in a JTable it gives me the ids before said, instead of the names as I would like it to show them.

Is there any way to show that data, that is, the name of the patient, the description of the state?

    
asked by Gustavo Alexis 10.10.2017 в 20:52
source

1 answer

0

Yes, they are queries of related tables, not mentioning the names or fields of your tables so I will put a name to them, suppose we have the following tables:

Turnos
with the following fields:
Id_Turno , Id_Paciente_T , Id_Medico_T , Id_Estado_T

Pacientes
with the following fields:
Id_Paciente , Nombre_completo , Fecha_Nacimiento

Medicos
with the following fields:
Id_Medico , Nombre_Completo , Fecha_Nacimiento

Estados_Turnos
with the following fields:
Id_Estado_Turno , Nombre , Descripcion

And the query would be like this, I'll use alias for the tables to make it easier to reference the relationships

SELECT P.Nombre_Completo, M.Nombre_Completo, ET.Nombre 
FROM Turnos T, Pacientes P, Medicos M, Estados_Turnos ET
WHERE T.Id_Paciente_T = P.Id_Paciente
AND T.Id_Medico_T = M.Id_Medico
AND T.Id_Estado_T = ET.Id_Estado_Turno

And that would result in the fields that you would like to see

    
answered by 10.10.2017 / 22:57
source