bon*_*o46 17 sql ms-access insert not-exists
嗨,你们所有强大的SQLsuperheros在那里..任何人都可以救我从迫在眉睫的灾难和毁灭?
我正在使用Microsoft Access SQL.我想在一个表(table1)中选择不出现在另一个表(table2)中的记录,然后在table2中插入基于table1中记录的新记录,如下所示:
[table1] file_index:filename
[table2] file_index:celeb_name
我想要:
从table1中选择所有记录,其中[filename]与aud一样 ,其对应的[file_index]值在table2中不存在,带有[celeb_name] ='Audrey Hepburn'字段
有了这个选择,我想在[table2]中插入一条新记录
[file_index] = [table1].[file_index] [celeb_name] ='奥黛丽赫本'
[table1]中的[file_index]和[table2] [table1]中的一条记录与[table2]中的许多记录之间存在一对多的关系.
非常感谢
Tor*_*amo 16
这会吗?显然添加一些方括号和东西.不要自己进入Access.
INSERT INTO table2 (file_index, celeb_name)
SELECT file_index, 'Audrey Hepburn'
FROM table1
WHERE filename = 'aud'
AND file_index NOT IN (SELECT DISTINCT file_index
FROM table2
WHERE celeb_name = 'Audrey Hepburn')
Run Code Online (Sandbox Code Playgroud)