I have database like this http://sqlfiddle.com/#!9/e52c43
First query is :
SELECT m.tanggal, sum(mi.qty) as totalMuatan, mi.idPlastik
FROM tblMuatan m
LEFT JOIN tblMuatanIsi mi ON m.idMuatan = mi.idMuatan
WHERE m.tanggal='2020-03-15'
GROUP BY mi.idPlastik
The result is:
tanggal totalMuatan idPlastik
2020-03-15 85 1
2020-03-15 10 2
And second query is :
SELECT s.tanggal, sum(si.qty) as totalStok, si.idPlastik
FROM tblStok s
LEFT JOIN tblStokIsi si ON s.idStok = si.idStok
WHERE s.tanggal = '2020-03-15'
GROUP BY si.idPlastik
The result is :
tanggal totalStok idPlastik
2020-03-15 100 1
2020-03-15 200 2
I want to merge that 2 queries into single query with subquery
tanggal totalStok totalMuatan netTotal idPlastik
2020-03-15 100 85 15 1
2020-03-15 200 10 190 2
How to do the subquery in example above? Thank you for the support