我有两个带有4列的表
Table h1
----------
ID Name school home
1 A x 11
2 B y 12
3 C z 13
Table h2
----------
ID Name school home
1 A x 14
2 B s 15
3 D z 16
我想在表h1中插入表h2的数据,而不要重复检查某些列,我只想插入行ID 2和3
我正在尝试
使用NOT EXISTS:不起作用,使用NOT IN:我只能使用1列
答案 0 :(得分:0)
NOT EXISTS
为什么不起作用?在这里你可以去:
INSERT INTO table_h1 (ID, Name, school, home)
SELECT h2.ID, h2.Name, h2.school, h2.home
FROM table_h2 h2
WHERE NOT EXISTS (SELECT 1 FROM table_h1 h1 WHERE h1.id = h2.id AND h1.Name = h2.Name AND h1.school = h2.school);