1
Good morning, I’m new here and I’ve got a boring problem. Distinct does not solve my problem because the duplication is due to the fact that I had to make the relationship with other tables to seek information. SQL returns me two values with different supervisors for the same IDCALLED, as I do to display only one IDCALLED so as not to duplicate the records?
SELECT ch.idchamado,su.nome AS nomesupervisor,
e.nome,
ch.dataabertura,
ch.datafechamento,
ta.desctipoassunto
FROM sase_chamado ch
LEFT JOIN vw_app_consulta_escolas e
ON ch.idpj = e.idpessoa_juridica
LEFT JOIN sase_tipoassunto ta
ON ta.idtipoassunto = ch.idtipoassunto
LEFT JOIN sase_escolasusuario eu
ON eu.idpj = ch.idpj
INNER JOIN sase_usuario su
ON eu.idusuario = su.idusuario
WHERE ch.dataabertura BETWEEN to_date('01/01/16', 'dd/mm/yy') AND to_date('30/07/16', 'dd/mm/yy')
ORDER BY su.nome,
e.nome,
ta.desctipoassunto
the darn duplicity is of that kind here:
Do you just want an idchamado no matter how many su.nome you have? this goes for the rest of the fields?
– Marco Souza
Yes, in order not to bring 2 equal named. the only different field when duplicated is the supervisor’s own name.
– Samuel Greco
Samuel, if you do not want to generate a separate line for each supervisor you cannot show the result of the su.nome field in your SELECT (you must also remove from the ORDER BY clause and apply DISTINCT or GROUP BY). If you want to show his name with this structure you will always show 1 line for each supervisor name. It is possible (I don’t know specifically if in Oracle it is) to also join the name of N supervisors in a single column and row, but then you should change your SELECT considerably.
– Bruno Bermann
Turns out I can’t take your name off SELECT because I need it to assign the call there’s a supervisor’s name. distinct only works when the record is fully equal, but in my case the name of the supervisor changes when it duplicates, so do not funf
– Samuel Greco
In this case you can not group the lines really and should recover both results, if you have two lines (if I understood the logic of the query) is why there are two calls, each to a supervisor, and the other data are identical.
– Bruno Bermann
I just don’t know how to solve this kkk duplicity
– Samuel Greco