Query 1 :
SELECT '0' corder, ckode_coa, '' cnofaktur, DATE_FORMAT(CONCAT('2016','/','06','/','01'),'%d/%m/%Y') dtanggal,
'SALDO AWAL PERIODE' cketerangan, ndebit, ncredit FROM tbl_saldo WHERE cperiode=DATE_FORMAT(DATE_ADD(STR_TO_DATE(CONCAT('01/','06','/','2016'),'%d/%m/%Y'), INTERVAL -1 MONTH),'%Y%m') AND ckode_coa LIKE '1112019' AND substr(ckode_coa,length(ckode_coa),1)<>'0 ';
Output :
Query 2 :
SELECT '1' corder, d.ckode_coa, h.cnofaktur, h.dtanggal, h.cketerangan, d.ndebit, d.ncredit FROM tbl_gl_h h, tbl_gl_d d
WHERE dtanggal
BETWEEN '2016-06-30' AND '2016-06-30' AND ckode_coa LIKE '1112019' AND h.cnofaktur=d.cnofaktur
AND substr(ckode_coa,length(ckode_coa),1)<>'0'
Output :
Query 3 :
SELECT '0' corder, ckode_coa, '' cnofaktur,
DATE_FORMAT(CONCAT('2016','/','06','/','01'),'%d/%m/%Y') dtanggal,
'SALDO AWAL PERIODE' cketerangan, ndebit, ncredit FROM tbl_saldo
WHERE cperiode=DATE_FORMAT(DATE_ADD(STR_TO_DATE(CONCAT('01/','06','/','2016'),'%d/%m/%Y'), INTERVAL -1 MONTH),'%Y%m')
AND ckode_coa LIKE '1112019' AND substr(ckode_coa,length(ckode_coa),1)<>'0 '
UNION
SELECT '1' corder, d.ckode_coa, h.cnofaktur, h.dtanggal, h.cketerangan, d.ndebit, d.ncredit FROM tbl_gl_h h, tbl_gl_d d
WHERE dtanggal
BETWEEN '2016-06-30' AND '2016-06-30' AND ckode_coa LIKE '1112019' AND h.cnofaktur=d.cnofaktur
AND substr(ckode_coa,length(ckode_coa),1)<>'0'
Output :
Solusinya adalah ganti UNION dengan UNION ALL, dengan UNION ALL, row data yang duplikat tidak akan dibuang.
Referensi
- Using UNION to Append Result Sets, http://www.geeksengine.com/database/multiple-table-select/using-union.php