Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the main difference between sql and pl/sql?

1027


How do I filter in sql profiler?

947


what is oltp (online transaction processing)? : Sql dba

1013


What is delimiter sql?

921


How can I get the number of records affected by a stored procedure?

1000


Explain what is a field in a database and record in a database?

1015


Explain what is a view?

997


What is record variable?

922


How do I install microsoft sql?

981


how to enter binary numbers in sql statements? : Sql dba

921


What is equi join in sql?

1008


How to check if a column is nullable before setting to nullable?

1055


what are different types of keys in sql?

1064


what is an alias command? : Sql dba

1007


what is online transaction processing (oltp)? : Sql dba

935