I am trying to join 2 tables with in a SUM IF statement. the code is as under:
SELECT prod_code, description, description1, quant,
SUM(IF(newsales.location = '05-P', newsales.quant,''))P,
SUM(IF(newsales.location = '10-L', newsales.quant,'')) L,
SUM(IF(newsales.location = '12-M', newsales.quant,'')) M,
SUM(IF(newsales.location = '11-BI', newsales.quant,'')) Bi,
SUM(IF(newsales.location = '14-BR', newsales.quant,'')) Br
from newsales, stock
where newsales.prod_code = stock.prod
group by prod_code
But it gives an incorrect output, but if I romove the join statement, it gives accurate resuly.
How to join the 2 tables ie newsles and stock so that the output remains right.
Any help is appreciated.
regards
SELECT prod_code, description, description1, quant,
SUM(IF(newsales.location = '05-P', newsales.quant,''))P,
SUM(IF(newsales.location = '10-L', newsales.quant,'')) L,
SUM(IF(newsales.location = '12-M', newsales.quant,'')) M,
SUM(IF(newsales.location = '11-BI', newsales.quant,'')) Bi,
SUM(IF(newsales.location = '14-BR', newsales.quant,'')) Br
from newsales, stock
where newsales.prod_code = stock.prod
group by prod_code
But it gives an incorrect output, but if I romove the join statement, it gives accurate resuly.
How to join the 2 tables ie newsles and stock so that the output remains right.
Any help is appreciated.
regards