Solved

Trying to setup a delete query in access based on results of another query.

Posted on 2012-03-16
7
280 Views
Last Modified: 2012-03-16
Here is my Delete query as of right now.
dltquery
I want to delete every row in the tblJobLog where tblJobLog.JobNum = qryJobLogDelCrit.jhJobNum.

Here is the sql for my current delete query;
DELETE tblJobLog.*
FROM tblJobLog INNER JOIN qryJobLogDelCrit ON tblJobLog.JobNum = qryJobLogDelCrit.jhJobNum


When I run this query as a Select query it will give me a list of JobNums that I would like to delete. I thought If I just changed it to a Delete query then it would delete those rows from tblJobLog.

When I try to run it I get the following error message;
Error
Thanks for the help!
0
Comment
Question by:SeyerIT
  • 3
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 350 total points
Comment Utility
Try this:

DELETE *
FROM tblJobLog
WHERE JobNum IN (SELECT jhJobNum FROM qryJobLogDelCrit)



It may also work without the *:

DELETE
FROM tblJobLog
WHERE JobNum IN (SELECT jhJobNum FROM qryJobLogDelCrit)
0
 
LVL 2

Author Comment

by:SeyerIT
Comment Utility
Is that rerunning qryJobLogDelCrit for every record in tblJobLog? Seems like that may be the case because it just hangs.. Is there a quicker method by chance?
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
What is the SQL for qryJobLogDelCrit?
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 150 total points
Comment Utility
<Is there a quicker method by chance?>

create a table from the result of running qryJobLogDelCrit, name it tmpTable
( or change the qryJobLogDelCrit into a make table query)

then run this delete query

DELETE *
FROM tblJobLog
WHERE JobNum IN (SELECT jhJobNum FROM tmpTable)
0
 
LVL 2

Author Comment

by:SeyerIT
Comment Utility
mbixup.. I'm sorry, I forgot to get all of my extra tables out of that query. qryJobLogDelCrit used to have a bunch of extra tables and calculations in it (I copied it from another table that had a bunch of stuff in it)

Once I deleted all the extra stuff from it, it ran almost immediately.

Thanks for the help there!

Thanks also Capricorn for your offering as well.. It would have solved the problem as well.
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
It sounds like you're set, but you probably could also work the criteria of qryJobLogDelCrit right into your delete query, to reduce it to a single query.  

That would be my preferred approach if the second query was not overly complex, and was where I was heading asking about the SQL
0
 
LVL 2

Author Comment

by:SeyerIT
Comment Utility
Gotcha. Thanks again!
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now