Solved

Cross-Table Delete

Posted on 2004-10-13
4
590 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
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://…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

10 Experts available now in Live!

Get 1:1 Help Now