MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 25th, 2013, 01:19 PM
rkatl rkatl is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 10 rkatl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 13 sec
Reputation Power: 0
Delete dupes with Join

I hope someone can help me with this. I'm trying to delete duplicate records from one table by joining another with a condition. For example:

info_table

InfoId, email, firstname, lastname

100, kris1ATyahoo.com, kris, Kot

101, kris1ATyahoo.com, kris, Kot

102, kirs1ATyahoo.com, kris, Kot

103, daveATyahoo.com, dave, Snider

104, daveATyahoo.com, dave, snider

105, tomATyahoo.com, tom, sawyer

106, tomATyahoo.com, tom, sawyer

tran_table

id, infoId, status

1, 100, 1

2, 101, 2

3, 102, 1

4, 103, 2

5, 104, 1

6, 105, 1

7, 106, 1

So, I want to delete from info_table with the below conditions.

I want to delete all the duplicate(by email) from infotable. However, I want to keep those whose status in tran_table is '2'.

Meaning, I want to delete the below:

Among 100,101,102 -- delete all except 101

Among 103,104 -- delete 104

Among 105, 106 -- delete any

Appreciate any help with the query--

Reply With Quote
  #2  
Old January 25th, 2013, 05:02 PM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,881 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 8 h 12 m 51 sec
Reputation Power: 813
Hi,

I don't really see what this has do to with duplicates. As far as I can tell, you simply remove all records with status <> 2, even if that doesn't leave any record for a given email address (like in your third case).

Anyway, check the MySQL manual for the USING clause of the DELETE statement. It allows you to join a table you want to delete from with other auxiliary tables.

Reply With Quote
  #3  
Old January 26th, 2013, 06:59 AM
rkatl rkatl is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 10 rkatl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 13 sec
Reputation Power: 0
Only difference is, I do not want to delete all the rows for 3rd case. I need to keep one of those records.


Quote:
Originally Posted by Jacques1
Hi,

I don't really see what this has do to with duplicates. As far as I can tell, you simply remove all records with status <> 2, even if that doesn't leave any record for a given email address (like in your third case).

Anyway, check the MySQL manual for the USING clause of the DELETE statement. It allows you to join a table you want to delete from with other auxiliary tables.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Delete dupes with Join

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap