How to retrieve Duplicate Rows only in a Table?
Suppose if a Table Name is "Education". It consists of
multiple columns. Then if we insert rows into this table
with duplicate records then how can we retrieve only
duplicate records from that table?

Answers were Sorted based on User's Feedback



How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / mohan

select count(*),column_name from table_name group by
column_name having count(*)>1

Is This Answer Correct ?    2 Yes 0 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / sarath

I don't know the exact intention of the above answers, but I am making mine clear that to find the TOTAL DUPLICATED RECORDS and THEIR COUNT OF REPETITIONS, the Pseudo code is:

Select col1,col2,col3,....,COLn count(*) from <TN>
group by col1,col2,col3,....,COLn having count(*) > 1;

Wish everybody complies with it, its tested.

Is This Answer Correct ?    1 Yes 0 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / a.balakrishna

select * from education where rowid in (select min(rowid)
from ex group by sno having count(*)>1);


100% it is true

Best of luck

9177509010

Is This Answer Correct ?    1 Yes 0 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / bhuvi

use self join and find the intersection

Is This Answer Correct ?    0 Yes 0 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / dev

SELECT * FROM TAB1 A WHERE A.ROWID > ANY
(SELECT B.ROWID FROM TAB2 WHERE A.COL1=B.COL1)

Is This Answer Correct ?    1 Yes 1 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / naresh

select * from emp where sal in(select sal from emp group by
sal having count(sal)>1);

Is This Answer Correct ?    1 Yes 1 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / "d"

select count(*),ss from dd group by
ss having count(*)>1

Is This Answer Correct ?    0 Yes 0 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / selvaraj v

In Oracle 10g :
-----------------

SQL> SELECT * FROM emp;

EMPNO ENAME JOB MGR HIREDATE
SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------
---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80
7500 20
7499 ALLEN SALESMAN 7698 17-DEC-80
1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81
1250 500 30
7566 JONES MANAGER 7839 02-APR-81
2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81
1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81
2850 30
7782 CLARK MANAGER 7839 09-JUN-81
2450 10
7788 SCOTT ANALYST 7566 19-APR-87
3000 20
7839 KING PRESIDENT 17-NOV-81
5000 10
7844 TURNER SALESMAN 7698 08-SEP-81
1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87
1100 20

7900 JAMES CLERK 7698 03-DEC-81
950 30
7902 FORD ANALYST 7566 03-DEC-81
3000 20
7934 MILLER CLERK 7782 23-JAN-82
1300 10
1 SELVA S/W ENG 7521 18-DEC-09
15000 1000 10
7521 WARD SALESMAN 7698 22-FEB-81
1250 500 30

16 rows selected.

The emp table contains DUPLICATE empno in this table. that's
2 empno's same. We find that empno's, Using the below query :

SQL> SELECT * FROM EMP
2 WHERE ROWID IN(SELECT MAX(ROWID) FROM EMP
3 GROUP BY EMPNO,ENAME,MGR,SAL,DEPTNO
4 HAVING COUNT(*)>1);

EMPNO ENAME JOB MGR HIREDATE
SAL COMM DEPTNO
---------- ---------- --------- ---------- ---------
---------- ---------- ----------
7521 WARD SALESMAN 7698 22-FEB-81
1250 500 30

In this emp table contains empno 7251 is 2 times.

Anyone Check this query. I'm expecting user comments...

Is This Answer Correct ?    0 Yes 0 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / jay k patel

SQL> select * from emp;

ENO ENAME DOJ DESGN ADDRESS BSAL
---------- ------- --------- ------- ------- ----------
1 jay 04-JAN-80 md vapi 50000
2 vijay 04-FEB-75 manager vapi 7000
1 ajay 12-JAN-77 dba vapi 9000
3 rajay 05-MAR-70 cleark vapi 5000
4 sujay 28-JAN-73 dba vapi 6000
5 jayesh 07-APR-74 cleark vapi 8000
7 jaymin 04-JAN-62 analyst vapi 4000
6 jaynis 10-MAY-69 dba vapi 9000
1 jayur 04-JAN-74 manager vapi 4000
12 jaynil 14-DEC-71 cleark vapi 2000

10 rows selected.

SQL> SELECT desgn , count(*)
2 FROM emp
3 GROUP BY Desgn
4 Having count(*) > 1 ;

DESGN COUNT(*)
------- ----------
cleark 3
dba 3
manager 2

SQL>

Is This Answer Correct ?    0 Yes 0 No

How to retrieve Duplicate Rows only in a Table? Suppose if a Table Name is "Education". ..

Answer / kumargvk

select * from education a where rownum>(select max(rownum)
from education b where b.rno=b.rno)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

a. Can you delete data from a View. b. If Yes, can you delete it if there are multiple tables c. If No, can you delete if there is single source table which is joining.

4 Answers   CGI, IBM,


what is index? : Sql dba

0 Answers  


What are the two characteristics of a primary key?

0 Answers  


Can pl sql procedure have a return statement?

0 Answers  


Two Methods of retrieving SQL?

7 Answers   Atiric Software, Microsoft, Oracle, TCS, Wipro,






Which command is used to delete a package?

0 Answers  


How do you rename a table in sql?

0 Answers  


what are the different index configurations a table can have? : Sql dba

0 Answers  


What are the types of records?

0 Answers  


What is a record in a database?

0 Answers  


What is a table partition?

0 Answers  


what is a primary key? : Sql dba

0 Answers  


Categories