Prevent duplicate records in left outer join

0

I have tried to use distinct but without success ... result should be

SELECT
distinct
prd.ID_CPF_EMPRESA,
prd.prd_codigo ,
prd.cat_codigo ,
prd.prd_descricao,
prd.prd_preco ,
prd.prd_img ,
prd.prd_det_1 ,
prd.prd_det_2 ,
prd.prd_ativo ,
IFNULL(adc.adc_descricao,0) as adicional
FROM produtos prd
left outer join adicionais adc
on adc.prd_codigo = prd.prd_codigo 
where prd.cat_codigo = 35 and prd.prd_ativo='S'

    
asked by anonymous 31.10.2017 / 19:26

1 answer

0

Let's say that it's a logic problem, you have 2 tables joining together but maybe the ids that repeat are not in the table that you put DISTINCT, but in the other one (Just an assumption since I do not know 2 tables quoted) ...
Try to put a groupby in the 'additional' table or else do the distinct in it. Example:

group by adc.prd_codigo

or:

SELECT DISTINCT adc.prd_codigo,...
    
31.10.2017 / 19:29