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
What is root password?
What, if a table has one column defined as TIMESTAMP?
How to upload a large file through phpmyadmin in mysql?
change column name and make a unique column so we get no dupes.
Which is faster mysql or mongodb?
How to get help information from the server?
What do you need to connect php to mysql?
How to see the create table statement of an existing table?
Why use stored procedures in mysql?
How to display nth highest salary from a table in a mysql query?
How does mysql clustering work?
What are ddl statements in mysql?
How do I rename a table in mysql?
What is tee command in mysql?
Is foreign key indexed mysql?