Solved

DELETE Query is not working...

Posted on 2004-10-20
4
1,210 Views
Last Modified: 2007-12-19
Hi Guys,
This is a problem I already solved, but I still have no idea why I had the problem in the first place,
so I am asking you to explain what was wrong with my query.

The query deletes records from table1 based on some joins with table2.
The exactly same SELECT works perfectly, but the deletion, gives me an error that I need to specify a table, or that I cannot delete from this table.
Here's the query:

    DELETE table1.*
    FROM table1 INNER JOIN table2 ON (table1.name=table2.name) AND (table1.address=table2.address)
    WHERE (((table1.email) Is Not Null))

the Preview shows the correct answers, and if I make it a SELECT instead of DELETE, it shows all the rows correctly too.
But this query cannot be executed...

The way I solved it was:

DELETE *
FROM table1
WHERE ID IN
(
    SELECT table1.ID
    FROM table1 INNER JOIN table2 ON (table1.name=table2.name) AND (table1.address=table2.address)
    WHERE (((table1.email) Is Not Null))
);

Now, can anybody PLEASE explain why the hell didn't the first query work?!
0
Comment
Question by:Boris Aranovich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 500 total points
ID: 12355756
You cannot delete using a query with joins - that's just the way it is unfortunately. Essentially, the engine doesn't know which table(s) you want to delete from even if you specify it with the table1.*.
0
 
LVL 3

Author Comment

by:Boris Aranovich
ID: 12355767
That's what I thought...
But, this is a bit stupid, IMHO...
"DELETE table1.* FROM table1" should be clear enough for the engine to know what am I trying to delete...
Besides, the documentation of Access wrote that I can use JOIN in _any_ FROM statement...
Couldn't find there anything that will explain that it could break the query... :/
Oh well... it's unfortunate that sometimes I have to use Access for ease of work, because of the visual interface and etc.

Is there a way that I can integrate MS Access interface (application) with some MySQL database perhaps, and MySQL syntax queries?
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12355788
I'm not really familiar with MySQL but Access works just fine as a front end to MySQL - you could run your queries as pass-through queries assuming MySQL supports that kind of thing - sorry, I've never used it in this way, but I know many people have used it as a back end (I use SQL Server when I have to, personally).
0
 
LVL 3

Author Comment

by:Boris Aranovich
ID: 12355804
Alright, thanks a lot, I will explore and try to figure how it works.
If I won't manage, I know where to come back to ask questions ;)
Thanks again.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

695 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