I have a table with 4 fields: field1
, field2
, field3
, field4
and I want to insert registers that not exists if (field1
and field2
and field3
) exists.
My query is this :
INSERT INTO mytable (`id_est`, `id_course`, `date`,`nro`)
VALUES ('5','7','2020-06-11','')
where id_est and id_course
and date not in (select id_est, id_course, date from mytable)
I want two things:
Know Why with this query appears the next error:
#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 'WHERE `id_est` and `id_course` and `DATE` not in (select `id_estudiante`,' at line 1
How can I transform this query according to the CodeIgniter syntax?
$data =array( ) $this->db->insert('mytable', $data); $this->db->where_is_not();
Thanks. The field id_est
and id_course
and date
are key and I wan't that is repeated.
Clarification: I need to insert data in mytable
with the next fields: id_est
, id_course
, date
and nro
. I need that id_est
and id_course
and date
(all these three fields are unique), for example:
id_est id_course date nro
1 1 date1 1
1 1 date2 3
1 1 date2 2 (this register is not insert because id_est=1 and id_course=1 and date2 is in my table)