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 a cursor? : Mysql dba
How do I kill a mysql query?
What are the critical issues you have resolved in your company
How do I start mysql client?
How do you rename a table?
How to update a root password.
What does "i_am_a_dummy flag" do in mysql?
What is longblob?
How do I make an action query?
Why do we use mysql?
How do I install the latest mysql on ubuntu?
What is the data source name for mysql?
Explain the difference between procedure and function in mysql?
List some comparisons operators used in mysql?
Is mysql better than oracle?