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 download mysql on my laptop?

1 Answers  


how to Return total number of rows.

1 Answers  


How many threads can mysql handle?

1 Answers  


Why do you think it is advised to not to use guid and character columns as clustered index arrays?

1 Answers  


how to take mysql database structure backup

6 Answers  


What is regex in mysql?

1 Answers  


What is database engine in mysql?

1 Answers  


What is tee command in mysql?

1 Answers  


What is the difference between mysql_connect and mysqli_connect?

1 Answers  


How do I tune a mysql query?

1 Answers  


What is session variable in mysql?

1 Answers  


How do I connect to a mysql database?

1 Answers  


Categories