Mysql-5
插入忽略條件
我需要插入一些可能有重複的記錄。要覆蓋/跳過的列是
mytable.email
並且mytable.fooFlag
應該是 1。我想出了這樣的事情:
INSERT IGNORE INTO mytable VALUES ('somemailaddress') ONLY IF 'somemailaddress' DOES NOT EXIST AND fooFlag = 1
如果
如果
INSERT INTO mytable (email) SELECT sourcetable.email FROM sourcetable WHERE sourcetable.email NOT IN (SELECT mytable.email from mytable where mytable.fooflag=1)