Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cross-Table Delete

Posted on 2004-10-13
4
Medium Priority
?
602 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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

782 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