Thursday, March 22, 2012

Remove Duplicate Rows from mysql table

How to delete duplicate rows from MySQL table 

It's very simple

In my case as per the requirement admin can import csv file and all the data we need to store in MySQL database

Before inserting data i need to check the data already existed or not ? :)

Find the below code

            $query="SELECT * FROM table";
            $result=mysql_query($query);
            echo mysql_error();
            while($row = mysql_fetch_array($result)){
                $query1="SELECT * FROM table WHERE order_number='".$result_data[0]."' ";
                $result1=mysql_query($query1);
                $count = mysql_num_rows($result1) - 1;
                mysql_query("DELETE FROM table WHERE order_number='".$result_data[0]."' ");
                //echo "deleted $row[1] ";
            }
After this code INSERT the records


No comments:

Post a Comment