新しい行を MySQL テーブルに挿入しようとしていますが、挿入する値の 1 つがテーブルに既にある行にない場合のみです。
たとえば、私がやっている場合:
insert into `mytable` (`id`, `name`) values (10, `Fred`)
テーブル内の他の行に既にname = 'Fred'
. これはどのように行うことができますか?
ありがとう!
編集
私が試したこと(正確な声明を投稿することはできませんが、ここに表現があります):
INSERT IGNORE INTO mytable (`domain`, `id`)
VALUES ('i.imgur.com', '12gfa')
WHERE '12gfa' not in (
select id from mytable
)
エラーがスローされます:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE '12gfa' not in ( select id from mytable)' at line 3