Duplicity with JOIN

Asked

Viewed 37 times

1

Hi, I need a hand, if you can help me, I appreciate.

I need to query between three tables, however, when I search the query is returning me duplicate lines:

SELECT US.NOME AS PROFISSIONAL, AG.NOMEPACIENTE AS NOME_PACIENTE, CONV.NOME 
AS CONVENIO, AG.NUMEROPRONTUARIO, AG.DATA,
P.CODIGOAMB AS DESCRICAO_ATENDIMENTO, P.TOTALTAXAS AS TOTAL_TAXAS, 
P.TOTALDIARIAS AS TOTAL_DIARIA
FROM T_AGENDACONSULTAS AS AG
JOIN T_USUARIOS AS US ON AG.USUARIO = US.CODIGO
JOIN T_CONVENIOS AS CONV ON AG.CONVENIO = CONV.CODIGO
JOIN T_PACIENTESCONTAS AS P ON AG.NUMEROPRONTUARIO = P.PACIENTE
WHERE DATA BETWEEN '2019/06/01' AND '2019/06/30' AND NOMEPACIENTE='augusto prazeres'

1 answer

2

  SELECT DISTINCT US.NOME AS PROFISSIONAL, AG.NOMEPACIENTE AS NOME_PACIENTE,
         CONV.NOME AS CONVENIO, AG.NUMEROPRONTUARIO, AG.DATA, P.CODIGOAMB AS
         DESCRICAO_ATENDIMENTO, P.TOTALTAXAS AS TOTAL_TAXAS, P.TOTALDIARIAS AS
         TOTAL_DIARIA
    FROM T_AGENDACONSULTAS AS AG JOIN T_USUARIOS AS US ON AG.USUARIO = US.CODIGO 
         JOIN T_CONVENIOS AS CONV ON AG.CONVENIO = CONV.CODIGO
         JOIN T_PACIENTESCONTAS AS P ON AG.NUMEROPRONTUARIO = P.PACIENTE
   WHERE DATA BETWEEN '2019/06/01'
         AND '2019/06/30' AND NOMEPACIENTE='augusto prazeres'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.