Cross-Table Delete

Posted on 2004-10-13
Last Modified: 2010-05-18
Simplified situation:  I have a table that I want to delete entries from based on entries in another table:



My query so far:
DELETE FROM Table1 USING Table2 WHERE Table1.user = Table2.user AND = 'something I know';

Not sure if this is the right query, but this is where I am right now.  Currently, it's giving me the error:
ERROR 1066: Not unique table/alias: 'Table2'

However, 'Table2' is unique as far as I can see.. no other tables, or fields are named that.
Question by:Chireru
  • 3
LVL 15

Accepted Solution

jdlambert1 earned 125 total points
ID: 12299794
You need a reference to table 1 in the USING clause so it can join:

DELETE FROM Table1 USING Table1, Table2 WHERE Table1.user = Table2.user AND = 'something I know';
LVL 15

Expert Comment

ID: 12299798
You can also do it this way:

DELETE Table1 FROM Table1, Table2 WHERE Table1.user = Table2.user AND = 'something I know';

Author Comment

ID: 12299849
Yup, that tiny change did it, thanks :)
LVL 15

Expert Comment

ID: 12299877
>tiny change did it
I once spent all day trying to figure out an error, and finally discovered a missing period was the only problem...

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to retrieve data related to last id inserted into database 3 55
RDBMS and No sql database 4 56
MySQL Memory Keeps Increasing 4 33
two ways encryption with php 3 24
Both Easy and Powerful How easy is PHP?  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  Very powerful.  But a…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

816 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

7 Experts available now in Live!

Get 1:1 Help Now