0
I have the command SQL that doesn’t work:
SELECT
GAT_requisicao.id_GATrequisicao as 'ID Requisição',
GAP_atendimento.id_GAPatendimento as 'ID Atendimento',
GR_paciente.nome_GRpaciente as 'Nome Paciente',
GR_setor.nome_GRsetor as 'Setor Requisitante',
GR_setor.nome_GRsetor as 'Setor Executante'
FROM
GAT_requisicao, GAP_atendimento, GR_paciente, GR_setor
WHERE
GAT_requisicao.GAPatendimento_id = GAP_atendimento.id_GAPatendimento
AND GAP_atendimento.paciente_GAPatendimento = GR_paciente.nrcarteira_GRpaciente
AND GAT_requisicao.setorReq_GATrequisicao = GR_setor.id_GRsetor
AND GAT_requisicao.setorExec_GATrequisicao = GR_setor.id_GRsetor;
On the table GAT_requisicao
I have 2 columns:
- setorReq_GATrequisicao
- setorExec_GATrequisicao
One is saved the requesting sector and the other the executing sector and these columns are filled with FK
table GR_setor
, but what happens:
If I ask on select
to see the setorReq
and the setorExec
and connect the 2 tables, does not return me anything, I can only make 1 call at a time, or call setorExec
the table GR_setor
or call setorReq
the table GR_setor
, the 2 links at the same return the return comes null.
Isn’t it necessary to put in from the tables that are being used in the command? Type: FROM Gat_requisicao, Gap_care, Gr_patient, Gr_sector
– D. Watson
Yes, they’re in the clause
from
, but with theinner join
in front.– Ricardo Pontual
I got it. I tested this command that you suggested and didn’t work, Mysql Workbench returns this error: "Error Code: 1054. Unknown column 'Gr_sector.name_GRsector' in 'field list'". Although within the Gr_sector table there is the column name_GRsector.
– D. Watson
puts
GR_setor_req.nome_GRsetor
andGR_setor_exec.nome_GRsetor
– Rovann Linhalis
Thanks @Rovannlinhalis and Ricardo Pontual, after that change worked.
– D. Watson