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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to display top 10 rows in mysql?

574


What is prepared statement in mysql?

484


What is dirty read and phantom read?

441


How to create table show example

528


Where’s database data actually stored?

517






What is data types in mysql?

474


What are the advantages of mysql?

531


How would you get the current date in mysql?

646


Can you tell which of the following where clauses is faster?

440


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

670


How does mysql store data?

516


What's the difference between mysql and sql server?

468


what is database white box testing? : Mysql dba

508


Why we use mongodb instead of mysql?

478


How do I rename a mysql database?

490