0

I mean that when I want to insert a record into MySQL, I first check if it exists.

This is usually used when dealing with user registration, I should check the username submitted whether or not has been registered. I do not want to use a unique index because I have a logical delete in my db.

I try to user select ... for update, but for data not exist, it doesn't work well.

Amrutha Saj
  • 1,309
  • 11
  • 33
Li.xz
  • 1

1 Answers1

0

For an example:

insert into user_table(id,user_name,deleted)
select 1,'new user name',0 from user_table where `user_name`<>'new user name' and deleted=0 limit 1;
Joyson
  • 86
  • 2