Solved

DELETE Query is not working...

Posted on 2004-10-20
4
1,207 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
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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.

728 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

13 Experts available now in Live!

Get 1:1 Help Now