Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14217 reviews 1686 hosting providers

Questions & Answers

Removing identical data between 2 tables

Jun 9, 2013 by SaraSX
Hello,

I want to remove  all unsubscribed accounts from Mysql accounts table. The unsubscribed user accounts are all available in another table(subscribed accounts). I want Mysql to take all the accounts from the unsubscribed table and  remove it from the subscribed accounts table. How do I achieve this? Can anyone please help?

Thanks

2 Answers

0 votes
Jun 9, 2013 by tareq101
Use the below code  in a php cron job

`DELETE FROM Table1 WHERE ID IN (SELECT ID FROM Table2)`
Since you are deleting.. its better to make copies of your tables before you proceed with this command
0 votes
Jun 9, 2013 by TopNet
try this
DELETE FROM t1 USING `Table1` t1 INNER JOIN `Table2` t2 WHERE t1.username=t2.username