Javatpoint Logo
Javatpoint Logo

SQL DELETE DUPLICATE ROWS

If you have got a situation that you have multiple duplicate records in a table, so at the time of fetching records from the table you should be more careful. You make sure that you are fetching unique records instead of fetching duplicate records.

To overcome with this problem we use DISTINCT keyword.

It is used along with SELECT statement to eliminate all duplicate records and fetching only unique records.

SYNTAX:

The basic syntax to eliminate duplicate records from a table is:

EXAMPLE:

Let us take an example of STUDENT table.

ROLL_NONAMEPERCENTAGEADDRESS
1AJEET MAURYA72.8ALLAHABAD
2CHANDAN SHARMA63.5MATHURA
3DIVYA AGRAWAL72.3VARANASI
4RAJAT KUMAR72.3DELHI
5RAVI TYAGI75.5HAPUR
6SONU JAISWAL71.2GHAZIABAD

Firstly we should check the SELECT query and see how it returns the duplicate percentage records.

PERCENTAGE
63.5
71.2
72.3
72.3
72.8
75.5

Now let us use SELECT query with DISTINCT keyword and see the result. This will eliminate the duplicate entry.

PERCENTAGE
63.5
71.2
72.3
72.8
75.5




Please Share

facebook twitter google plus pinterest tumbler

Learn Latest Tutorials