Solved

Cross-Table Delete

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

Table1
----------
user
otherdata

Table2
----------
user
group

My query so far:
DELETE FROM Table1 USING Table2 WHERE Table1.user = Table2.user AND Table2.group = '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.
0
Comment
Question by:Chireru
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
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 Table2.group = 'something I know';
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12299798
You can also do it this way:

DELETE Table1 FROM Table1, Table2 WHERE Table1.user = Table2.user AND Table2.group = 'something I know';
0
 
LVL 5

Author Comment

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

Expert Comment

by:jdlambert1
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...
 
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

15 Experts available now in Live!

Get 1:1 Help Now