Hello
note: to the editors: please edit the title if have a better one :)
my question is:
I have two tables in my database
-----------
| table1 |
|----------|
| id |
|text |
===========
-----------
| table2 |
|----------|
| id |
|text |
===========
table1 is 600,000 records
table2 is 5,000,000 records !!:)
what is the best way to delete all the records in table2 that are not in table1
I main by the way -the fastest way because I don't want to wait 4 hours to complete the process
do you have something better than the following code:
<?PHP
$sql = "select text from table2";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$text = $row["text"];
$sql2 = "select id from table1 where text = '$text'";
$query2 = mysql_query($sql2) or die(mysql_error());
$result2 = mysql_num_rows($query2);
if($result2==0){
$sql3 = "delete from table2 where text = '$text'";
$query3 = mysql_query($sql3) or die(mysql_error());
}
}
?>
Thanks