yesterday I asked this question: if in mysql insert statement and the answer works very well.
The problem is that I need to insert a row in my table if a value doesn’t exist.
f.e.
If('x' NOT EXIXTS in (select campoX from table) then
insert into table (...) values (...) etc.
How can I do? on the internet I can’t find an answer 🙁
I assume your table is named tbl.
DUALis purely for the convenience of people who require that all SELECT statements should have FROM and possibly other clauses. MySQL may ignore the clauses. MySQL does not require FROM DUAL if no tables are referenced.As some other mentioned, you could use
INSERT IGNOREstatement here IF your campoX is an unigue Or primary key field.