Query to find duplicate rows from table [message #624531] |
Tue, 23 September 2014 07:17 |
gaganmadhu
Messages: 11 Registered: April 2008
|
Junior Member |
|
|
Team,
We need your help in getting duplicate rows from query. Mapping Table will have old and New employee ID's and trasaction table like JOB will have the details like Employee ID, Name, Address Etc. (Employee ID is Key field in Job table). Need a query to fetch "only duplicate rows" from job table
Create two tables, Mapping and Job :
SQL> CREATE TABLE EMPL_MAPPING (EMPLID_OLD VARCHAR (11), EMPLID_NEW VARCHAR (11)) ;
Table Created.
SQL> CREATE TABLE JOB (EMPLID VARCHAR (11), NAME VARCHAR (30) , ADDRESS VARCHAR (30));
Table Created.
Insert rows into Mapping table :
SQL> INSERT INTO EMPL_MAPPING VALUES ('12348', 'ABC48');
1 row created.
SQL> INSERT INTO EMPL_MAPPING VALUES ('12349', 'ABC49');
1 row created.
SQL> INSERT INTO EMPL_MAPPING VALUES ('12345', 'ABC45');
1 row created.
SQL> INSERT INTO EMPL_MAPPING VALUES ('12346', 'ABC46');
1 row created.
Insert rows into Job table :
SQL> INSERT INTO JOB VALUES ('12345', 'TEST5', 'FL');
1 row created.
SQL> INSERT INTO JOB VALUES ('12346', 'TEST6', 'FL');
1 row created.
SQL> INSERT INTO JOB VALUES ('12347', 'TEST7', 'FL');
1 row created.
SQL> INSERT INTO JOB VALUES ('12348', 'TEST8', 'FL');
1 row created.
SQL> INSERT INTO JOB VALUES ('12349', 'TEST9', 'FL');
1 row created.
SQL> INSERT INTO JOB VALUES ('ABC48', 'TEST8', 'FL');
1 row created.
SQL> INSERT INTO JOB VALUES ('ABC49', 'TEST9', 'FL');
1 row created.
Query output should look like:
SQL> select * from JOB ;
EMPLID NAME ADDRESS
----------- ------------------------------ ------------
12348 TEST8 FL
12349 TEST9 FL
ABC48 TEST8 FL
ABC49 TEST9 FL
4 rows selected.
|
|
|
|
|
Re: Query to find duplicate rows from table [message #624548 is a reply to message #624542] |
Tue, 23 September 2014 08:03 |
gaganmadhu
Messages: 11 Registered: April 2008
|
Junior Member |
|
|
Hi Michel..
With duplicate i mean, data having old employee ID as well as New employee Id.
When we query Job table, in the results we should get 4 rows (2 for each employee with old employee ID row and new employee ID row)
Regards,
Madhu
|
|
|
|
|
|