Re: Comparing multiple Mysql tables to find duplicates
| From: | John W. Holmes | Date: | Fri, 30 Jan 2004 17:54:41 +0000 |
| Subject: | Re: Comparing multiple Mysql tables to find duplicates | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-176372@lists.php.net to get a copy of this message | ||
From: "Chris Bruce" <chris@idextrus.com>
> Mysql 3.23.54.
>
> My first thought was to load the output from the tables into an array
> and they use a foreach and in_array to create a list of dups, but I
> wanted to see if there was an easier way.
Ah, in that case, my other query won't work. :)
This should:
<?php
$query = "SELECT list1.email FROM master_list, list1 WHERE master_list.email
= list1.email";
$result = mysql_query($query) or die(mysql_error());
while($r = mysql_fetch_assoc($result))
{ $email_list .= "'{$row['email']}',"; }
$email_list = substr($email_list,0,-1); //remove last comma
$query = "DELETE FROM list1 WHERE email IN ($email_list)";
$result = mysql_query($query) or die(mysql_error());
?>
Repeat for other tables.
---John Holmes...