T
T
Tenebrius2018-03-26 13:13:45
MySQL
Tenebrius, 2018-03-26 13:13:45

How to insert a row only if there is none?

Let's say we have a table:

col1 | col2 | col 3
--------------------
v031 | v034 | v999
v031 | v385 | v555

It is necessary to avoid adding another line "v031", "v034", "v999'. That is, if the values ​​in all three columns completely match, the line should not be inserted.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan., 2018-03-26
@LaRN

You can use the not exists construct in an insert query
https://dev.mysql.com/doc/refman/5.7/en/exists-and...

A
Adamos, 2018-03-26
@Adamos

UNIQUE index on these three columns + INSERT IGNORED

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question