i have table called barang
and when i want to insert into the table with this code
INSERT INTO barang(kode,deposit,brand)
VALUES('13212321','1232131','12312321');
it turns error #1242 - Subquery returns more than 1 row
i already search into SO but didnt found out with just case as mine, which part i skip on this?
UPDATE
as mr @P.salmon said here's my trigger on before insert
, sir
BEGIN
SET NEW.tanggal = NOW();
SET NEW.kategori_nama = (SELECT kategori.nama from kategori JOIN barang WHERE
kategori.kode = barang.kategori);
SET NEW.hargadepresiasi = NEW.hargabeli * 2 / 8;
END
column for kategori
and barang
table :
---------------------
| kategori |
---------------------
| kode |
| nama |
| no |
---------------------
for barang
table
---------------
| barang |
---------------
| kode |
| nama |
| kategori |
| kategori_nama |
---------------
so basically, on kategori_nama
column in barang
table is still null and i want to fill it with nama
on kategori
table with kategori.kode = barang.kategori
CodePudding user response:
run this by hand for the value in your update that gives the error
SELECT kategori.nama from kategori JOIN barang WHERE
kategori.kode = barang.kategori
then you should see the multiple records - then you can decide which of those records your really intend and rewrite this part of the trigger
these might be what you need:
SELECT distinct kategori.nama from kategori JOIN barang WHERE
kategori.kode = barang.kategori
or
SELECT min( kategori.nama ) from kategori JOIN barang WHERE
kategori.kode = barang.kategori