X

How to delete duplicate Rows from Table using SQL Query

As developer, you may have come across this situation when you need to delete duplicate rows from table.

For ex.

Table : country

countryCode    countryName
IN India
US United States
US United States
UK United Kingdom
CA Canada
IN India
IN India

Suppose, table has very less duplicate rows then you can do using Group query and can delete duplicate rows but if Table has many duplicate values then you can do it by creating one temporary table as below.

(Please take backup of your database before following below steps.)

Step 1:
Create temporary table with same table structure. You can do this from phpmyadmin. Click on Table. Choose Operation tab. In “Copy table to (database.table):” option, give temporary table name. For ex. countrytemp. Choose “Structure only” option and click on “Go”. Now, you will have countrytemp table with same structure as country table has.

Step 2:
Execute below query.

Insert into countrytemp select distinct * from country

After running this query, you will have required distinct data in countrytemp table. Now, you can delete or can rename of country table to country_bkup for backup and rename countrytemp to country table.

Your final result will look this for above table.

Table : country

countryCode countryName
IN India
US United States
UK United Kingdom
CA Canada

Thats All. You are done. You will have same table with unique data. Każdy oferuje szereg bezpłatnych kredytów (wirtualnych żetonów) do gier online za darmo automaty.Spis sprawdzonych automaty do gry za darmoz najwyższymi wskaźnikami jakości wszystkich ważnych parametrów którymi musi posiadać dostojny kasyno gry za darmokasyna można znaleźć tu! Na onlinekasyno48.pl możecie grać automaty do gry za darmo i . Onlinekasyno48 Każdy oferuje szereg bezpłatnych kredytów (wirtualnych żetonów) do gry online za darmo automaty.Spis sprawdzonych automaty do gry za darmo automaty.Spis sprawdzonych automaty do gier platformowych, wybierz sam automaty do gier we właściwy sposób. Wybór automatów do gry za darmo automaty.Spis sprawdzonych automaty do gier we .

This post was last modified on April 13, 2016 5:27 pm

Categories: Database
Chetan Patel: Chetan Patel is blogger, writes on Tech News, current trends, Gadgets Reviews, Website owner guide and Tips. You can connect him at <a href="https://plus.google.com/118385579556796801405?rel=author">Google+</a> & <a href="https://www.facebook.com/patecj">Facebook</a>.