Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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

share|improve this question

1 Answer 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'
share|improve this answer
    
Nope, there is an error :1222 - The used SELECT statements have a different number of columns –  Naufal Muhammad Feb 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 at 5:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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