I
I
Ibishka2020-05-14 13:38:26
MySQL
Ibishka, 2020-05-14 13:38:26

INSERT if not in the database?

In Google they say to do it through UNIQUE and they also offer this option

INSERT INTO table_listnames (name, address, tele)
VALUES ('Rupert', 'Somewhere', '022')
WHERE NOT EXISTS (
    SELECT name FROM table_listnames WHERE name='value'
);

But what's the best option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-05-14
@Ibishka

There is no INSERT ... WHERE in MySQL.
So UNIQUE the index and INSERT IGNORE or INSERT ... ON DUPLICATE KEY UPDATE.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question