Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:26:21+00:00 2026-06-11T01:26:21+00:00

I am trying to create a delete query to remove records from one table,

  • 0

I am trying to create a delete query to remove records from one table, based on whether or not one of the field exists in another master table. The situation is that I am importing new records into a database, but I want to remove the records that have already been imported, i.e. that already have an account in the master table. The field I need to join on, however is not equal: it is prefixed with a constant three letter code XYZ.

 tbl_to_import.Account     master_table.Account
 123456                    XYZ.123456
 345678                    XYZ.345678

To avoid using a join in the delete query I tried the following:

 Delete tbl_to_import.*
 From tbl_to_import
 Where Exists( Select master_table.Account From master_table 
 Where master_table.Account =  ("XYZ."& tbl_to_import.Account) ) = True;

However, the query gets hung up in Access. I’m not sure what I’m doing incorrectly. I don’t get an error message, but the query runs without producing anything and I eventually stop it. In this situation, tbl_to_import has 2,700 records and master_table has 50,000 records. Additionally, I am connecting to the master_table via ODBC.

Originally, I constructed two queries using a join to perform the delete. tbl_to_import.Account has a primary key called ID. One query, qry_find_existing_accounts, located the ID numbers in tbl_to_import for which there exists a corresponding account in master_table.Account:

 SELECT DISTINCTROW tbl_to_import.ID AS DELETEID
 FROM tbl_to_import LEFT JOIN master_table 
      ON ("XYZ."& tbl_to_import.Account) = master_table.Account
 WHERE ((("XYZ." & [Account])=[master_table].[Account]));

Then I used this query to construct the delete query:

 DELETE DISTINCTROW tbl_to_import.*, tbl_to_import.ID
 FROM tbl_to_import RIGHT JOIN qry_find_existing_accounts 
      ON tbl_to_import.ID =qry_find_existing_accounts.DELETEID
 WHERE (((tbl_to_import.ID)=[qry_find_existing_accounts].[DELETEID]));

The query qry_find_existing_accounts worked fine; however, when I tried to run the second query to delete, I got the error: Could not delete from specified tables. Typically, when I get this error, it is because I have not selected unique records only, however, I used DISTINCTROW in both queries.

Any ideas what I am doing wrong and how I can accomplish what I need to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:26:23+00:00Added an answer on June 11, 2026 at 1:26 am

    I’d go with a simpler nested SQL statement:

    Delete tbl_to_import.*
    From tbl_to_import
    Where "XYZ." & tbl_to_import.Account In
    (Select master_table.Account From master_table);
    

    This should be fairly fast, especially if your Account fields are indexed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to delete the records from the users table in mysql, the
Here is what im trying to do explained in a query DELETE FROM table
Using Doctrine , I am trying to delete records in a single table based
String query = CREATE TABLE IF NOT EXISTS platforms ( + id INTEGER UNSIGNED
I'm trying to create a cron job which will automatically delete .jpg files from
I keep getting these errors when trying to delete rows from a table. The
I am trying to write a SQL query that returns rows from a table
I am trying to write some SQL to automatically delete some records from the
I am trying to use design-view to create a delete query, to delete all
I'm trying to run a query on a very simple table but I'm not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.