mysql 带条件的插入语句

insert into person_table (uid,pname,age)
select 2,"李四",20 from dual
where not exists
(select id from person_table where uid=2 )

表:person_table

列名 : (id,uid,pname,age)

要保存的纪录:(uid,pname,age)values (2,"李四",20)

当表中不存在 uid为2的记录时保存该数据

 

你可能感兴趣的:(mysql)