Mysql 如果行不';不存在相同的值

Mysql 如果行不';不存在相同的值,mysql,sql,Mysql,Sql,在mySql中,如何插入一行如果某一特定电子邮件不存在行,我需要从数据库表中创建一千行缺失的行,我有一个包含五千封电子邮件的文件,我不知道表中哪些电子邮件已经存在,哪些不存在 我试图像这样为每一行构造一个sql语句,但它是无效的sql语法 insert into License (email) select unique 'person@gmail.com' where not exists (select 1 from License where email='person@gmail.com

在mySql中,如何插入一行如果某一特定电子邮件不存在行,我需要从数据库表中创建一千行缺失的行,我有一个包含五千封电子邮件的文件,我不知道表中哪些电子邮件已经存在,哪些不存在

我试图像这样为每一行构造一个sql语句,但它是无效的sql语法

insert into License (email) select unique 'person@gmail.com' where not exists (select 1 from License where email='person@gmail.com');

电子邮件不是表的主键,也不一定是唯一的,我所关心的是,如果没有电子邮件地址的记录,请添加记录,否则不要添加记录。

您可以通过为
where
使用
from
子句来解决此问题:

insert into License (email)
    select email
    from (select 'person@gmail.com' as email) t
    where not exists (select 1 from License l where l.email = t.email);
但是,在一条语句中进行所有插入更有意义:

insert into License (email)
    select t.email
    from database_table t
    where not exists (select 1 from License l where l.email = t.email);
如果您只需要1000个,可以添加
限制1000