在使用主键作为检查器检查表B中是否有重复项时,如何在表A中插入数据?
答案 0 :(得分:0)
如果您要从test_data
表中的complete_train_data2
表插入test_data
,则ID尚不存在:
INSERT INTO test_data
SELECT * FROM complete_train_data2
WHERE NOT EXISTS
(SELECT * FROM complete_train_data2 WHERE test_data.id=complete_train_data2.id);
或者,如果您不想保留其他列中的数据,请尝试以下操作:
INSERT INTO test_data
SELECT id,'b', 0,0,0,0,0,0,0,0,0,1,0 FROM complete_train_data2
WHERE NOT EXISTS
(SELECT * FROM complete_train_data2 WHERE test_data.id=complete_train_data2.id);