473,699 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Inner Join Delete query

68 New Member
Hi,
I have 2 tables [VMSU-ILT-Main] and [VMSU-ILT-Sub]
The VMSU-ILt-Main Table contains info about a person on the main form, the VMSU-ILT-Sub Table contains info about the subform on the main form. they both have [IDNumber] as ehe linked fied, and I am trying to delete records on both tables by Date, the date is only stored in vMSU-ILT-main table. I am getting error when I try to run my query:
Expand|Select|Wrap|Line Numbers
  1. DELETE [VMSU-ILT-Main].*,[VMSU-ILT-Sub].*
  2. FROM [VMSU-ILT-Main] INNER JOIN [VMSU-ILT-Sub] ON [VMSU-ILT-Main].[IDNumber] = [VMSU-ILT-Sub].[IDNumber] WHERE [VMSU-ILT-Main].[Date]= "-740";
The error I get states "cannot delete from specified tables"
I have also tried changing my first(delete) line to Delete [VMSU-ILT-Main].*, [VMSU-ILT-Sub] *
and I get error "jet engine does not recognise VMSU-ILT-Main .*"
I have read though the threads and haven't found a solution that works, I have even tried deleting the child table records first but still I get the error message "cannot delete from specified tables."
aparently w/ an * you cannot specify criteria as with SQL .
thank for helping
Feb 28 '08 #1
8 23740
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Trevor. Problem is that Delete is intended to delete records in a single table, so you can't use the join query to do so.

If you set the relationship between the two underlying tables to Cascade Delete you will be able to delete associated records on the many side of the relationship when you delete records on the one side. You can then delete the main table records and the associated records using the single DELETE statement listed below:
Expand|Select|Wrap|Line Numbers
  1. DELETE [VMSU-ILT-Main].*
  2. FROM [VMSU-ILT-Main] WHERE [VMSU-ILT-Main].[Date]= "-740";
  3.  
I am assuming that your where condition on the Date field is correct, even though you are referring to a string that does not look like a date to me.

Regards

Stewart

ps Cascade Delete is not set by default because it can be quite dangerous - delete one record and lose a whole lot more in one go!
Feb 28 '08 #2
Trevor2007
68 New Member
I tried to set up my cascade delete, but to click cascede delete I have to click inforce integrety ,
as you know from my previous post that the only linking field is IDNumber,
but when I try to create my link, I get an error message saying that the main table does not contain records from the sub table , example there may be records related to the employees in the related table but no records in the for the employee in the primary table.
I could just add a date field to the vmsu-ILT-sub table and delete by date , that would give me the same end result I would like to try to avoid having to do that.
Thanks Trevor 2007
Feb 28 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I tried to set up my cascade delete, but to click cascede delete I have to click inforce integrety ,
as you know from my previous post that the only linking field is IDNumber,
but when I try to create my link, I get an error message saying that the main table does not contain records from the sub table...
Hi Trevor. The error means that there are records in your sub-table that don't have matching IDs in the main table. Because the 1-to-many relationship between the tables is already broken Access cannot set up the 1-M relationship. Your current link between the main form and subform will hide these unmatched records (since the link will only show the ones that do exist in both tables). It is possible to find all records in the subtable which aren't matched in the main table with a left-join query:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Select [VMSU-ILT-Sub].*
  3. FROM [VMSU-ILT-Sub] LEFT JOIN [VMSU-ILT-Main] ON [VMSU-ILT-Main].[IDNumber] = [VMSU-ILT-Sub].[IDNumber] WHERE ([VMSU-ILT-Main].[IDNumber]) Is Null;
  4.  
At least you would be able to find the unmatched records then decide what to do with them, and whether or not to leave the relationship between the tables an informal one.

-Stewart
Feb 28 '08 #4
Trevor2007
68 New Member
So once the table link is broken its broken and can't be fixed?

it's looking like the easiest way to to do this is just to add the date to the sub table and just delete by date rather then haveing 2 + quries to do the same job?
I have no clue why access must be so difficult w/ inner join delete quries.
Thanks, Trevor 2007
what are your thaughts?
Feb 28 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
So once the table link is broken its broken and can't be fixed?
it's looking like the easiest way to to do this is just to add the date to the sub table and just delete by date rather then haveing 2 + quries to do the same job?
I have no clue why access must be so difficult w/ inner join delete quries.
Thanks, Trevor 2007
what are your thaughts?
Sorry if I have left you confused, Trevor. The relationship is broken at present because of the unmatched records; find these and resolve them back to matched records, or delete them if they are no longer required, and you certainly can fix the relationship.

You can use the left-join query suggested in the last response (or any other suitable method) to find the unmatched records on the many-side of the table relationship. These may be orphaned records left by deletion of the one-side records at some stage, leaving the many-side records with no match. Access itself would have prevented such a situation from arising in the first place if referential integrity had already been set. It really is best for the integrity of your data to find the unmatched records and deal with them. You will then be able to fix the link between the two tables properly - and you can then make full use of relational cascade and update properties that you can't when the 1-many is broken.

Sorry again for confusing you.

-Stewart
Feb 28 '08 #6
Trevor2007
68 New Member
Sorry if I have left you confused, Trevor. The relationship is broken at present because of the unmatched records; find these and resolve them back to matched records, or delete them if they are no longer required, and you certainly can fix the relationship.

You can use the left-join query suggested in the last response (or any other suitable method) to find the unmatched records on the many-side of the table relationship. These may be orphaned records left by deletion of the one-side records at some stage, leaving the many-side records with no match. Access itself would have prevented such a situation from arising in the first place if referential integrity had already been set. It really is best for the integrity of your data to find the unmatched records and deal with them. You will then be able to fix the link between the two tables properly - and you can then make full use of relational cascade and update properties that you can't when the 1-many is broken.

Sorry again for confusing you.

-Stewart
I finaly got the relationship between the 2 table to work, but I am now getting the error " specify the table to delete from"
and my query in SQLview looks like:
Expand|Select|Wrap|Line Numbers
  1. DELETE [VMSU-ILT-Main].Date
  2. FROM [VMSU-ILT-Main] INNER JOIN [VMSU-ILT-Sub] ON ([VMSU-ILT-Main].IDNumber = [VMSU-ILT-Sub].IDNumber) AND ([VMSU-ILT-Main].IDNumber = [VMSU-ILT-Sub].IDNumber)
  3. WHERE ((([VMSU-ILT-Main].Date)<Date()-740));
Do you know why access has to be a pain in the @$$ when it comes to delete innerjoin queries?
Thanks for your continuing help
Mar 2 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
I finaly got the relationship between the 2 table to work, but I am now getting the error " specify the table to delete from"
and my query in SQLview looks like:

DELETE [VMSU-ILT-Main].Date
FROM [VMSU-ILT-Main] INNER JOIN [VMSU-ILT-Sub] ON ([VMSU-ILT-Main].IDNumber = [VMSU-ILT-Sub].IDNumber) AND ([VMSU-ILT-Main].IDNumber = [VMSU-ILT-Sub].IDNumber)
WHERE ((([VMSU-ILT-Main].Date)<Date()-740));

Do you know why access has to be a pain in the @$$ when it comes to delete innerjoin queries?
Thanks for your continuing help
Hi Trevor. Delete queries in Access are single-table only, so whatever way you try to join tables in a DELETE query it will result in similar issues. If you have indeed set Cascade Delete between the main and sub tables, you won't need the inner join at all. The Cascade Delete will remove the sub-table entries matching the main table entries when the query is run. Adjusted SQL for the single-table delete is below:
Expand|Select|Wrap|Line Numbers
  1. DELETE [VMSU-ILT-Main].Date
  2. FROM [VMSU-ILT-Main] WHERE ((([VMSU-ILT-Main].Date)<Date()-740));
I'm glad you are making progress with this, and recognise the frustration that such an apparently simple thing to do turns out not to be.

Regards

Stewart
Mar 3 '08 #8
NeoPa
32,569 Recognized Expert Moderator MVP
Access (Jet) SQL is limited in this area (as compared with other SQL engines - MSSQL; Oracle; etc). I often use a work-around which is to update the record(s) first using an update query (less picky) then use the updated data to determine which records to delete.
A typical example is to search the dataset for records to delete and change their Name or Description fields to something like "DeleteMe". The next step is a simpler one, to delete all records with "DeleteMe" as the Name or Description.
It's a bit of a kludge, but is a workable method nevertheless.
Mar 3 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2215
by: Beringer | last post by:
I have the following query in Access: SELECT a.interest_parent_id, a.interest_element_id, b.alr_category_id AS interest_category_id, a.allergy_parent_id, a.allergy_element_id, c.alr_category_id AS allergy_category_id FROM (AllergyDrugPermutation AS a INNER JOIN alr_category_drug_map AS b ON a.interest_element_id = b.drug_id) INNER JOIN alr_category_drug_map AS c ON a.allergy_element_id = c.drug_id and all is well!
12
18667
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U LEFT JOIN UserTeamAssoc UTA ON UTA.userID = U.userID, Role R, UserRoleAssoc URA, Team T WHERE U.userID = URA.userID AND URA.roleID = R.roleID AND U.userId > 1
1
4173
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
2
1616
by: Robert | last post by:
I built a query in Query Analyzer and mapped it to Access 2002. The result set returned is identical except cells in some records in the Access result have #Deleted. This cast a shadow of doubt on the reliability of Access. Am I doing something incorrect? Comments? Access query SELECT .Account, .Region_nm, .Site, dbo_Results. FROM INNER JOIN ( INNER JOIN (
5
4043
by: jason.evans | last post by:
Hi there. I am having an intrigueing problem. I have a query which left joins another query to itself twice. The original query is derived from a linked table in SQLServer 2000. When I run it on my pc It runs fine. However for other users in the office, it behaves as an inner join. ie it only returns the records fo which the join fields equal each other. This happens on every other pc
3
4428
by: s_wadhwa | last post by:
Hi, I'm trying to convert MS Access 97 .mdb application to Access 2003 .adp application with SQL Server as Backend. I'm having trouble converting Access Query into SQL Query. The Query is given below: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SELECT DISTINCTROW Buildings.BuildingNumber,
4
52434
MMcCarthy
by: MMcCarthy | last post by:
To view Access queries in SQL rather than Access query design - open the query design window and change the view to SQL: Select Statement SELECT FROM ; Append Statement INSERT INTO (, , ) VALUES ('value1', #value2#, value3); This assumes value1 is a string, value2 is a date and value 3 is some other datatype
1
1341
by: sqlnew123 | last post by:
Hello, I am trying to convert the following Access query to SQL. I am not sure about the multiple INNER JOINS. Can you help please? SELECT dbo_ManagedRelationshipBooks.ShortAlias AS Account, dbo_Portfolios.PortfolioID, dbo_Portfolios.ProductID, dbo_MainManagedRelationships.IsTaxAware INTO Portfolios FROM (dbo_GO_Products INNER JOIN ((((dbo_ManagedRelationshipBooks INNER JOIN dbo_RelationshipPortfolioMix ON...
1
3287
by: Nettle | last post by:
Purpose: This is a Distribution List database. Function: Users create many different email distribution lists, tailoring each to fit their specific needs Wanted: Users can combine multiple distribution lists to create new ones. Sometimes, however, they discover they've made a mistake. Users would like to delete from a new distribution list only the records that belong to an old one. Technique (Short)
0
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7781
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.