Result with repeated records

Asked

Viewed 38 times

0

Good afternoon! I’m making a query, but the result is bringing repeated occurrences. there is some command for the query to only bring a record of each column?

follows script:

SELECT *
FROM HIS_LOTPES A, his_afasta c, FERIAS D, PESSOAL P
WHERE A.HLOT_PESS_CD_MAT = c.hafa_pess_cd_mat(+)
AND A.HLOT_PESS_CD_MAT = D.FERI_PESS_CD_MAT(+)
AND P.PESS_CD_MAT = D.FERI_PESS_CD_MAT(+)
and a.hlot_dt_inicio <> c.hafa_dt_inicial(+)
and a.hlot_dt_saida <> c.hafa_dt_final(+)
and a.hlot_dt_inicio < feri_dt_inicio(+)
and a.hlot_uorg_cd_ent = '2'
and a.hlot_uorg_ufed_sg = 'DF'
and a.hlot_uorg_cd_org = '1'
and a.hlot_uorg_cd_gab = '101'
and a.hlot_uorg_cd_dep = '2'
and a.hlot_uorg_cd_div = '0'
and a.hlot_uorg_cd_set = '1'
and a.hlot_uorg_cd_sec = '1'
AND A.HLOT_DT_INICIO > '01/01/2015'

Thank you!

  • Have you tried using the distinct? Select distinct * from HIS_LOTPES...

  • I think I’ve seen an identical question these days, I get the impression this is a duplicate. The problem was exactly a Join with an N:N ratio, probably the same as what happens here. Incidentally, implicit joins mounted with WHERE usually get harder to read, analyze and adjust, I would suggest making explicit, choosing the right junction types according to the desired result.

1 answer

0

You can be using the distinct option.

SELECT DISTINCT * FROM tabela

But it will be grouped if the whole row is the same, if a column is different it will bring (because if a column is different the record is not equal).

Browser other questions tagged

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