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

How do I copy an entire mysql database?

0 Answers  


What is definer in mysql trigger?

0 Answers  


What is procedural api?

0 Answers  


HOW TO FIND display the total number of weeks in the year of 1998 IN EMP TABLE

0 Answers  


How do I completely remove mysql from windows?

0 Answers  






Can we rename database in mysql?

0 Answers  


Explain the difference between delete and truncate.

0 Answers  


How do I stop a query in mysql workbench?

0 Answers  


How to calculate the difference between two time values?

0 Answers  


What is clob datatype?

0 Answers  


Does mysql use tcp or udp?

0 Answers  


How can we change the name of a column of a table?

7 Answers  


Categories