Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete records in on table only

Status
Not open for further replies.

jslmvl

Vendor
Jan 26, 2008
268
GB
Hi,

By the help from tek-tipx.com I can run the sql:
"Select * From Table1 Left Join (Select Table2.[User] From Table2 Group By Table2.[User]) As t On Table1.[User]=t.[User]"

Now, I want to delete the selected records in Table1 something like
"Delete * From Table1 Left Join (Select Table2.[User] From Table2 Group By Table2.[User]) As t On Table1.[User]=t.[User] Where t.[User] Is Null"
without success. Can you tell me how to do that?

Thanks a lot for any help in advance.
 
I'd try this:
DELETE FROM Table1 WHERE [User] NOT IN (SELECT DISTINCT [User] FROM Table2)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Thank you for your suggestion which looks nice.

However, in my case (a very big .mdb), it took very very very long time to do
"Select FROM Table1 WHERE [User] NOT IN (SELECT DISTINCT [User] FROM Table2)"
while to do following is very fast
"Delete * From Table1 Left Join (Select Table2.[User] From Table2 Group By Table2.[User]) As t On Table1.[User]=t.[User] Where t.[User] Is Null
 
Sorry, I meant
while to do following is very fast
"Select * From Table1 Left Join (Select Table2.[User] From Table2 Group By Table2.[User]) As t On Table1.[User]=t.[User] Where t.[User] Is Null"
and that is why I want to do something like

"Delete * From Table1 Left Join (Select Table2.[User] From Table2 Group By Table2.[User]) As t On Table1.[User]=t.[User] Where t.[User] Is Null
 
What about this ?
Delete Table1.* From Table1 Left Join Table2 On Table1.User=Table2.User Where Table2.User Is Null

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I tested that can work but again runs endless....
 
When the delete command is being run, do you have the Table1 records locked by another query, user form, or other?

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top