Solved

Cross-Table Delete

Posted on 2004-10-13
4
595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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