Insert INTO NOT EXISTS SQL access

后端 未结 3 1075
失恋的感觉
失恋的感觉 2020-12-21 12:05

I am trying to insert records from another table into a table in Access using sql. I have pasted the statement below. I want to insert the records that exist in ImportMetr

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-21 13:08

    You need a correlation clause. The subquery just checks whether or not the table is empty. Something like:

    INSERT INTO ShouldImportMetricsIDsTable( [Formulary ID], [Market Segment] )
        SELECT im.[Formulary ID], im.[Market Segment]
        FROM ImportMetricsIDs01262015 as im
        WHERE NOT EXISTS (SELECT 1
                          FROM ShouldImportMetricsIDsTable as sim
                          WHERE im.[Formulary ID] = sim.[Formulary ID] AND
                                im.[Market Segment] = sim.[Market Segment]
                         );
    

提交回复
热议问题