Hi all - I am trying to create a single sql statement that will delete unmatch recoreds. It is a fairly simple action on the surface, however it involves a subquery that is a UNION. I keep getting errors. Can someone point me in the right direction?. I can create the UNION query, and then create another query that uses the Union query. However, I would really like to combine the two into one SQL statement so it can be placed in VBA without any queries saved in the db. Here's the "delete" query:
Here's the UNION query (qryAllActiviti es in the above):
Again, I would like a single SQL that combines the two. My thought is that this would be a Subquery, but I can't get it to work...
Thanks in advance.
Code:
DELETE tblActMap.Job, tblActMap.Phase, tblActMap.Act, tblActMap.S_Key, qryAllActivities.S_Key FROM tblActMap LEFT JOIN qryAllActivities ON tblActMap.S_Key = qryAllActivities.S_Key WHERE (((qryAllActivities.S_Key) Is Null));
Code:
SELECT tblMnth.Job, tblMnth.Phase, tblMnth.ActID, tblMnth.S_Key FROM tblMnth GROUP BY tblMnth.Job, tblMnth.Phase, tblMnth.ActID, tblMnth.S_Key UNION SELECT tblProj.Job, tblProj.Phase, tblProj.ActID, tblProj.S_Key FROM tblProj GROUP BY tblProj.Job, tblProj.Phase, tblProj.ActID, tblProj.S_Key UNION SELECT tblWkly.Job, tblWkly.Phase, tblWkly.ActID, tblWkly.S_Key FROM tblWkly GROUP BY tblWkly.Job, tblWkly.Phase, tblWkly.ActID, tblWkly.S_Key;
Thanks in advance.
Comment