How we can eliminate duplicates without using distinct command?

Questions by Suganthidinesh

Showing Answers 1 - 54 of 54 Answers

siripala

  • Jun 10th, 2008
 

select column_with_duplicates, count(*) from table_name group by column_with_duplicates;

will give you distinct column values against number of ocurances

  Was this answer useful?  Yes

select * from  tale_name a  where rowid >any(select rowid from table_name b where a.col1=b.col1)
this query show duplicate record ina table and use delete command to eleminate duplicate record in the table.

hope this helpful to you

Ashish Sharma

  Was this answer useful?  Yes

vlaroyia

  • Sep 22nd, 2008
 

One,

delete
from xyz a
where rowid >=
(select min(rowid)
from xyz b
where a.e_id = b.e_id)


Two,

delete from
   xyz
where rowid in
 (select rowid from
   (SELECT
     ROWID,
     ROW_NUMBER()
    OVER
     (PARTITION BY E_ID ORDER BY E_ID) dup
    from xyz)
  where dup > 1);

Three,

If there are NULLS,

DELETE FROM
   table_name A
WHERE
   A.rowid >
   ANY (SELECT B.rowid
   FROM
      table_name B
   WHERE
      A.col1 = B.col1
   AND
      A.col2 = B.col2
   )

  Was this answer useful?  Yes

Assume  'location' is the column in 'Emp' table has several duplicates

EMP

Emp_Id   varchar(10)
Location  varchar(12)


 you can remove the duplicates using 'union' 

 select location from emp  union select location from emp ;

 this will strip the duplicates . 

  Hope this will help . 



 

debjit20

  • Apr 9th, 2010
 

Method 1:
SELECT col1, col2, col3 ….. --(list all the columns for which you want to eliminate duplicates)
 FROM (SELECT col1, col2, col3,….. --(list all the columns as above), COUNT(*)
          FROM table)

Method 2:
SELECT col1, col2, col3 ….. --(list all the columns for which you want to eliminate duplicates)
FROM table
UNION
SELECT col1, col2, col3 ….. --(list all the columns for which you want to eliminate duplicates)
FROM table (use the same table).

This union will remove the duplicates.

  Was this answer useful?  Yes

Nikhil I

  • Oct 12th, 2011
 

Suppose assume your table has 3 columns eno,ename,sal.

Code
  1. DELETE FROM emp WHERE rowid IN(SELECT eno,ename,sal,max(rowid) FROM emp GROUP BY eno,ename,sal);


The above query will eliminates the duplicate records from the table.

Code
  1. DELETE FROM emp WHERE rowid IN(SELECT eno,ename,sal,max(rowid) FROM emp GROUP BY eno,ename,sal);

  2.  

  Was this answer useful?  Yes

BHAGABAT

  • Apr 16th, 2016
 

SELECT COLUMN_NAME FORM TABLE_NAME GROUP BY COLUMN_NAME

  Was this answer useful?  Yes

sovenga_ngoveni

  • Feb 23rd, 2017
 

You can use the GROUP BY keyword at the end of your query

  Was this answer useful?  Yes

Palak

  • Apr 20th, 2017
 

By using Unique Command

  Was this answer useful?  Yes

Maria

  • May 16th, 2017
 

With GROUP BY statement.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions