I made this query but it gave me error just like in the title
INSERT INTO data_waktu_vaksinasi (id_binatang, id_vaksin, tanggal_vaksin, status_vaksin) VALUES
(1, 1, (SELECT DATE_ADD(max(tanggal_vaksin), INTERVAL 1 YEAR)) FROM data_waktu_vaksinasi, 'belum')
MySQL does allow the same table to be used for the source and target for inserts
. You just need to use the correct syntax:
INSERT INTO data_waktu_vaksinasi (id_binatang, id_vaksin, tanggal_vaksin, status_vaksin)
SELECT 1, 1, DATE_ADD(max(tanggal_vaksin), INTERVAL 1 YEAR), 'belum'
FROM data_waktu_vaksinasi;
Put the source table in subquery
to fix this problem. Mysql
does not allow same table in source and target for DML
operation's
INSERT INTO data_waktu_vaksinasi
(id_binatang,
id_vaksin,
tanggal_vaksin,
status_vaksin)
SELECT 1,
1,
dt,
'belum'
FROM (SELECT Date_add(Max(tanggal_vaksin), interval 1 year) AS dt
FROM data_waktu_vaksinasi)a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With