mrjameer Posted January 9, 2007 Share Posted January 9, 2007 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";}?>thanksmrjameer Quote Link to comment https://forums.phpfreaks.com/topic/33467-transfer-unique-records-from-one-mysql-table-to-another/ Share on other sites More sharing options...
HuggieBear Posted January 9, 2007 Share Posted January 9, 2007 The code looks fine to me. What happens if you execute it in phpMyAdmin?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33467-transfer-unique-records-from-one-mysql-table-to-another/#findComment-156645 Share on other sites More sharing options...
mrjameer Posted January 9, 2007 Author Share Posted January 9, 2007 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.thanksmrjameer Quote Link to comment https://forums.phpfreaks.com/topic/33467-transfer-unique-records-from-one-mysql-table-to-another/#findComment-156661 Share on other sites More sharing options...
HuggieBear Posted January 9, 2007 Share Posted January 9, 2007 Can you produce a data dump of the new table you've created in phpMyAdmin and then post it here.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33467-transfer-unique-records-from-one-mysql-table-to-another/#findComment-156669 Share on other sites More sharing options...
mrjameer Posted January 9, 2007 Author Share Posted January 9, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/33467-transfer-unique-records-from-one-mysql-table-to-another/#findComment-156684 Share on other sites More sharing options...
HuggieBear Posted January 9, 2007 Share Posted January 9, 2007 OK, I used the file you provided with the following SQL...[color=blue]INSERT INTO cc (email) SELECT DISTINCT email FROM bb[/color]...and it worked fine. There's nothing wrong with that code.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33467-transfer-unique-records-from-one-mysql-table-to-another/#findComment-156694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.