I want to make a query where I want to eliminate the
duplicate rows from the table.
For example :
Input : Table : NAME
Column1 Column2
India USA
USA India
UK India
India UK

The desired output that I want to eliminate the duplicates
Output
India USA
UK India
Thanks

Answers were Sorted based on User's Feedback



I want to make a query where I want to eliminate the duplicate rows from the table. For example :..

Answer / bramhendra kumar

CREATE TABLE #TBLD (NAME VARCHAR(20),NAME2 VARCHAR(20))
INSERT INTO #TBLD VALUES('India','USA'),('USA','India'),('UK', 'INDIA'),('India','UK')
WITH CTE
AS
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY NAME ORDER BY NAME) AS ROWNUM1,
ROW_NUMBER() OVER (PARTITION BY NAME2 ORDER BY NAME2) AS ROWNUM2
FROM #TBLD
)
DELETE FROM CTE WHERE ROWNUM1>1 OR ROWNUM2>1

SELECT * FROM #TBLD

TRUNCATE TABLE #TBLD

Is This Answer Correct ?    0 Yes 0 No

I want to make a query where I want to eliminate the duplicate rows from the table. For example :..

Answer / supriya

You want to delete the rows permanently or what

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More MySQL Interview Questions

Is mysql running ubuntu?

0 Answers  


What is heap table in mysql?

0 Answers  


What?s the default port for MySQL Server?

4 Answers   Yahoo,


What is difference between mysql and mariadb?

0 Answers  


What is trigger in mysql?

0 Answers  


For the database from the previous question, please give an SQL query which returns the invoice number of all invoices which contain the article with the number ?1234?. The query should be able to run under a MySQL 4.0 database.

1 Answers  


What are the different table present in MYsql?

3 Answers  


What is meant by sharding?

0 Answers  


Can I use mariadb instead of mysql?

0 Answers  


how to take mysql database backup?

0 Answers  


What is dirty read and phantom read?

0 Answers  


What is mysql ndb?

0 Answers  


Categories