GeekInterview.com
Series: Subject: Topic:
Question: 32 of 190

how we can eliminate duplicates without using distinct command?

Asked by: Suganthidinesh | Member Since Jun-2008 | Asked on: Jun 3rd, 2008

View all questions by Suganthidinesh

Showing Answers 1 - 14 of 14 Answers
siripala

Answered On : Jun 10th, 2008

View all answers by siripala

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

will give you distinct column values against number of ocurances

  
Login to rate this answer.

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

  
Login to rate this answer.

Use below query
select unique * from table_name;

  
Login to rate this answer.
vlaroyia

Answered On : Sep 22nd, 2008

View all answers by vlaroyia

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
   )

  
Login to rate this answer.

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 . 



 

Yes  3 Users have rated as useful.
  
Login to rate this answer.

SELECT UNIQUE deptno FROM emp;
It will give you distinct deptno.

  
Login to rate this answer.
ravishengg

Answered On : Oct 26th, 2009

View all answers by ravishengg


Table Name: Tbl
Columns:A B C

DELETE FROM Tbl  where rowid not in (select A,B,C,Max(rowid) from Tbl Group by A,B,C)

  
Login to rate this answer.

By using rowid we can elminate the duplicate records in a table


DELETE FROM TABLE_NAME WHERE ROWID NOT IN(SELECT MAX(ROWID) FROM TABLE_NAME GROUP BY COLUMN_NAME);

  
Login to rate this answer.

delete from tablename where rowin not in (select max(rowid) from tablename group by dup_col_name)

  
Login to rate this answer.
b.ganeshna

Answered On : Jan 30th, 2010

View all answers by b.ganeshna

Not only DISTINCT command and we can also use UNIQUE keyword.

  
Login to rate this answer.
debjit20

Answered On : Apr 9th, 2010

View all answers by debjit20

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.

  
Login to rate this answer.

SELECT * from emp
wheresal in (select sal from emp
Group by sal
having count(1)>1)

Thanks
ketarathhinenis

  
Login to rate this answer.
charchitsomani

Answered On : Mar 17th, 2011

View all answers by charchitsomani

By using JOIN command

  
Login to rate this answer.
Nikhil I

Answered On : 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.  

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.