Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 06-27-2008, 06:06 AM Repeated mails
Super Talker

Posts: 128
Name: Jose daSilva
Trades: 0
Hi

I'm trying t delete from my database a lot of repeated mails.

I use the following statment:

delete FROM emailsuk2 where email in (SELECT email FROM emailsuk2 GROUP BY email HAVING (COUNT( email) > 1 ))


but does not work giving me the following error:

#1093 - You can't specify target table emailsuk2 for update in FROM clause


What can be wrong?

Thanks
josil is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-27-2008, 08:37 AM Re: Repeated mails
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Your query is flawed at it's root.
Doing something like that will delete EVERY OCCURENCE of an email who is present several times in your table, not just the superfluous occurences.

I don't think you can do that without procedural language or php/asp/whatever...

You didn't specified which DB you are working on, so it may not work.
This was tested in postgresql:
Code:
delete
from emailsuk2 as em1
where 1< (
    select count(email)
    from emailsuk2 as em2
    where em1.email=em2.email
    group by email
);
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 06-27-2008 at 08:39 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-28-2008, 09:26 AM Re: Repeated mails
Super Talker

Posts: 128
Name: Jose daSilva
Trades: 0
Well does not wok either.
josil is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 09:56 AM Re: Repeated mails
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by josil View Post
Well does not wok either.
Quote:
Originally Posted by tripy View Post
You didn't specified which DB you are working on, so it may not work.
This was tested in postgresql:
over to you.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-28-2008, 03:26 PM Re: Repeated mails
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Yep. I stand by my words.
The query I gave you works in postgresql 8.3 without a hitch.
Tested and verified.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Repeated mails
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15249 seconds with 12 queries