Ask about Inner Join & Union

Posted on

Question :

i want to ask about my script this is doesn’t work. i need to help !

SELECT A.*,B.mat_nama,C.mats_nama 
FROM pengeluaran AS A 
INNER JOIN(material AS B) ON(A.mat_id = B.mat_id) 
INNER JOIN(mat_satuan AS C) ON(B.mat_satuan_id = C.mats_id)
WHERE A.mat_id = '7'
   AND A.pengeluaran_tgl BETWEEN '01/01/2014'  AND '02/28/2014'

UNION

SELECT A.*,B.mat_nama,C.mats_nama
FROM penerimaan_sub AS A 
INNER JOIN(material AS B) ON(A.mat_id = B.mat_id)
INNER JOIN(mat_satuan AS C) ON(B.mat_satuan_id = C.mats_id)
WHERE A.mat_id = '7'
  AND A.penerimaan_tgl BETWEEN '01/01/2014' AND '02/28/2014'

Error Notification in PhpMyadmin:

1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ON(A.mat_id = B.mat_id) INNER JOIN(mat_satuan AS C) ON(B.mat_satuan_id = C.mats_’ at line 1

Answer :

Try This

SELECT A.*,B.mat_nama,C.mats_nama 
FROM pengeluaran AS A 
INNER JOIN material AS B ON A.mat_id = B.mat_id 
INNER JOIN mat_satuan AS C ON B.mat_satuan_id = C.mats_id
WHERE A.mat_id = '7'
   AND A.pengeluaran_tgl BETWEEN '2014-01-01'  AND '2014-02-28'

UNION

SELECT A.*,B.mat_nama,C.mats_nama
FROM penerimaan_sub AS A 
INNER JOIN material AS B ON A.mat_id = B.mat_id
INNER JOIN mat_satuan AS C ON B.mat_satuan_id = C.mats_id
WHERE A.mat_id = '7'
  AND A.penerimaan_tgl BETWEEN '2014-01-01' AND '2014-01-28'

Leave a Reply

Your email address will not be published.