Duplicate column value, how to avoid? [duplicate]

2

How do I do exactly so that this Valuation value column does not have its values duplicated, ie instead of four result lines there would be only two.

SELECT p.nome,
       d.nome,
       c.valorAuxilio
FROM sca_pessoa p

INNER JOIN sca_dependente d ON p.idPessoa = d.idPessoa
INNER JOIN sispro_contrato c ON p.idPessoa = c.idPessoa

WHERE p.nome LIKE '%ADEMAR MAGA%'
AND c.idSituacaoContrato = 3 ORDER BY c.valorAuxilio;

    
asked by anonymous 08.04.2014 / 20:27

2 answers

3

You would have to group on top of the valorAuxilio field and use aggregate functions on top of the other columns.

SELECT GROUP_CONCAT(p.nome SEPARATOR ';'),
       GROUP_CONCAT(d.nome SEPARATOR ';'),
       c.valorAuxilio
FROM sca_pessoa p

INNER JOIN sca_dependente d ON p.idPessoa = d.idPessoa
INNER JOIN sispro_contrato c ON p.idPessoa = c.idPessoa

WHERE p.nome LIKE '%ADEMAR MAGA%'
AND c.idSituacaoContrato = 3 ORDER BY c.valorAuxilio;

GROUP BY c.valorAuxilio;

Reference:

GROUP BY (Aggregate) Functions

    
08.04.2014 / 20:35
0

Dude tries to use LEFT JOIN:

SELECT p.nome,
       d.nome,
       c.valorAuxilio
FROM sca_pessoa p

LEFT JOIN sca_dependente d ON p.idPessoa = d.idPessoa
LEFT JOIN sispro_contrato c ON p.idPessoa = c.idPessoa

WHERE p.nome LIKE '%ADEMAR MAGA%'
AND c.idSituacaoContrato = 3 ORDER BY c.valorAuxilio;

Put the description of the tables there so we can take a look.

    
08.04.2014 / 21:06