2010-11-29 501 views

回答

3

只需添加的狀況您的「IF」的INSERT的WHERE例如

INSERT INTO People 
(FirstName,LastName,Email) 
SELECT @FirstName,@LastName,@Email WHERE @Email NOT IN (SELECT Email FROM People) 

如果電子郵件地址表中已經存在,那麼在SELECT將返回沒有行,因此沒有插入將發生

1

如何:

insert into table1 
    (select * from table2 where id not in 
     (select id from table1))