when i'm running my program, the results of the number instead make a number merge and make the number into many results.

SELECT pengiriman_supply.po_nomor, 
       ((sum(pengiriman_supply.jumlah))-(ifnull(masuk.terima,0))) as total  
FROM pengiriman_supply 
INNER JOIN data_supplier 
    ON pengiriman_supply.idsupplier = data_supplier.id_supplier  
INNER JOIN data_barang 
    ON pengiriman_supply.idbarang = data_barang.idbarang  
LEFT JOIN masuk 
    on masuk.refrence = pengiriman_supply.po_nomor  
WHERE pengiriman_supply.tanggal BETWEEN date_sub(curdate(), interval 120 day) AND curdate()  
GROUP BY pengiriman_supply.po_nomor 
ORDER BY pengiriman_supply.po_nomor desc;

the results is this

enter image description here

  • 1) Query text do not match to result screenshot (fieldnames); 2) Not full GROUP BY (non-aggregated fields values are random within group); 3) Desured output not shown; 4) Totally - unclear. – Akina Nov 12 at 7:03
  • There is nothing "double" ...your group by sums up per Reference_Number pulled from pengiriman_supply.po_nomor. It's just coincidence that several "Totals" are the same ... but as Akina says ... only because mysql allows it doesnt make it good sql. You should give all used columns in the group by part OR in aggregate functions like sum() - you cover 2 columns .. but you select 4 ... – eagle275 Nov 12 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.