I meet an error like this:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘TANAH’%’ AND a.id_bencana=b.id_bencana AND a.id_daerah=c.id_kelurahan AND c.id_k’ at line 1
SELECT a.tgl_kejadian,b.nama_bencana,a.alamat,c.nama_kelurahan,d.nama_kecamatan,a.kerugian,a.keterangan FROM data_kejadian a , data_bencana b, kelurahan c, kecamatan d WHERE b.nama_kejadian LIKE '%'TANAH'%' AND a.id_bencana=b.id_bencana AND a.id_daerah=c.id_kelurahan AND c.id_kecamatan=d.id_kecamatan AND a.tgl_kejadian BETWEEN '2019-12-03' AND '2020-01-10'
Advertisement
Answer
Learn to write queries cleanly!
- Use proper
JOIN
syntax. - Use meaningful table aliases.
Your problem is misplaced quotes:
SELECT a.tgl_kejadian, b.nama_bencana, a.alamat, k.nama_kelurahan, kc.nama_kecamatan, a.kerugian, a.keterangan FROM data_kejadian a JOIN data_bencana b ON a.id_bencana = b.id_bencana JOIN kelurahan k ON a.id_daerah = c.id_kelurahan JOIN kecamatan kc ON kc.id_kecamatan = k.id_kecamatan WHERE b.nama_kejadian LIKE '%TANAH%' AND a.tgl_kejadian BETWEEN '2019-12-03' AND '2020-01-10';