473,378 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Access Inner Join Delete query

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 23715
Stewart Ross
2,545 Expert Mod 2GB
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
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 Expert Mod 2GB
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
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 Expert Mod 2GB
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
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 Expert Mod 2GB
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,556 Expert Mod 16PB
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
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...
12
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...
1
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...
2
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...
5
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...
3
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...
4
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 (, , )...
1
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,...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.