MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 16th, 2004, 04:39 PM
nevillemehta nevillemehta is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: India
Posts: 64 nevillemehta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 7
MySql Sub Queries...

While i was searching for a solution to my problem i found out that my current mysql version doesnt support sub queries. I am stuck with a problem whose solution i can think of only as a sub-query.

I'll eliminate all useless details and narrate the problem.
Tablename: links
id(PK) url
1 abc
2 xyz
3 abc
4 cde
5 tyu
and the list goes on

Notice the duplicates in the url field (for eg. id1 and id3 where url = 'abc'). Can someone please tell me some way of REMOVING the duplicates however leaving any ONE of them? The current MYSQL query i thought of using subqueries was;

delete from links where id IN (select id from links group by
url having count(*) >= 2)

The inner query displays all the id's of links who have 2 or more url entries. The outer query deletes the row with that id.

Can someone tell me a better option WITHOUT subqueries?

Thanks

Reply With Quote
  #2  
Old March 16th, 2004, 04:46 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
You could always work up a little script that first does the subquery and stores the results in an array, then goes through the array (or joins it for use in an "IN" clause) to do the actual deletion.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MySql Sub Queries...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT