5
How can I make an Insert with a Where condition?
I have the following query:
INSERT INTO `registro`(`id`, `username`)
values
('','USER_1'),
('','USER_2'),
('','USER_3')
It will add a new user to the record table. Only that I need him to check if this user already exists in DB, if it already exists he should not enter. Such verification shall be made only for the column username
.
I read in some places that the INSERT does not accept the WHERE, in this case as it should be done?
I was exactly writing this answer. The fastest leads.
– William Aparecido Brandino
@WilliamAparecidoBrandino hahahahhaa.
– Danielle Arruda torres
@Daniellearrudatorres And how to make more than one line to be inserted?
– Wendler
@Wendler
SELECT
will take care of it.– William Aparecido Brandino
So, is that I need to include more than one record in the same command, then I must repeat the whole query, or just the
SELECT
?– Wendler
Put the part of your code so we can better understand your need.
– Danielle Arruda torres
I updated the question there, in this case it will enter 3 records.
– Wendler
If you need to check all values, it is necessary to pass all of them by select, as they are different values and then the return may be different too.
– Danielle Arruda torres
And how to do this by repeating all the SELECT? Sorry, I am very lay in mysql.
– Wendler
Because of 1, in SELECT 1, in WHERE NOT EXISTS?
– ElvisP