0

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

1

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'
  • Nope, there is an error :1222 - The used SELECT statements have a different number of columns – Naufal Muhammad Feb 14 '14 at 3:22
  • 2
    This is because of the tables "pengeluaran" and "penerimaan_sub" have different set or number of columns.Since query uses UNION so i would suggest expose all the common columns from these two table instead of A.* . – Narendra Feb 14 '14 at 5:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.