Jump to content

transfer unique records from one mysql table to another


mrjameer

Recommended Posts

hi,

i have a table.in that there are nearly 12000 email ids.in that may be 1000 email ids duplicates(repeated twice).i want to transfer the unique email ids from old table to new table.i tried the code but it is transfering the all ids but not unique.how to solve this.any of your help will be appreciated.here is my code
<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("mrj",$conn4);
$sql="INSERT INTO cc (email) SELECT DISTINCT email FROM bb";
$result=mysql_query($sql,$conn4) or die(mysql_error());
if($result)
{
echo "transfered";
}
else
{
echo "not";
}
?>

thanks
mrjameer


Link to comment
Share on other sites

hi,

i executed it in phpmyadmin but it is showing all the rows.i have created a table with only id,email fields.inserted 5 records with some duplicates and executed to display the distinct records.it is working but when i transfer the this data in to some other it is not working.


thanks
mrjameer
Link to comment
Share on other sites

the records for this bb table has been dumped from text file.the code for moving data from text file to table is
<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("mrj",$conn4);

$fp = fopen("file.txt", "r");

if($fp)
{
  while( !feof($fp) )
  {
      $line = fgets($fp, 1024);
      list($email) = explode(',', $line);

      // do inserts here, i.e.
      $query = "INSERT INTO bb (email) VALUES
                ('$email')";
      $result=mysql_query($query,$conn4);

  }
    echo "ok";
}
else
{
  echo 'unable to open file for read';
}
?>


CREATE TABLE `bb` (
  `email` text NOT NULL
) TYPE=MyISAM;

#
# Dumping data for table `bb`
#

INSERT INTO `bb` VALUES ('Jas5646@hotmail.com\r\n');
INSERT INTO `bb` VALUES ('JSD5819595@hotmail.com\r\n');
INSERT INTO `bb` VALUES ('Jer5d@hotmail.com\r\n');
INSERT INTO `bb` VALUES ('Jlm5mam@hotmail.com\r\n');
INSERT INTO `bb` VALUES ('Jas5646@hotmail.com\r\n');
INSERT INTO `bb` VALUES ('Jlm5mam@hotmail.com\r\n');
INSERT INTO `bb` VALUES ('JWC6467@hotmail.com\r\n');
INSERT INTO `bb` VALUES ('Jsx66ie6@hotmail.com\r\n');


CREATE TABLE `cc` (
  `email` text NOT NULL
) TYPE=MyISAM;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.