i have table called 'barang' with this trigger
so basically i used trigger to update column kategori_nama
, based on another column on my table called kategori
with barang.kategori = kategori.kode and then update table barang.kategori_nama
with kategori.nama
when i build this trigger, why it turns error like this #1442 - Can't update table 'barang' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
UPDATE
i did like @Solarflare advice to look at this answer https://stackoverflow.com/a/42333142/17202382
so i did this into my trigger (because there are several process so i combine into one trigger)
DROP TRIGGER IF EXISTS `update_date`;CREATE DEFINER=`root`@`localhost` TRIGGER `update_date` BEFORE INSERT ON
`barang` FOR EACH ROW BEGIN SET NEW.tanggal = NOW(); UPDATE barang t1 INNER JOIN kategori t2 ON t1.barang = t2.kode SET t1.kategori_nama = t2.nama; SET NEW.hargadepresiasi = NEW.hargabeli * 2 / 8; END