Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How can i fetch duplicate data's from a table?

I completed my graduation last year and i am getting started with SQL. can anyone help me to solve this query. 

Table name is Employee and it has the following fields EMPNO, ENAME, SAL, JOB, DEPTNO. I want to find only the duplicate data's from the table. I tried using aggregate functions i couldn't get the required result. 

user-image
Question added by Balaji Prakash , Data Analyst , Systech Solutions
Date Posted: 2017/05/01
Rupesh Kumar
by Rupesh Kumar , Consultant in Oracle BRM , Cubastion Consulting Pvt. Ltd.

Expecting EMPNO is essential/primary key and ENAME has duplicate values then you can use following SQL.

select ENAME from EMPLOYEE group by ENAME having count(ENAME) > 1;

heidar yousef
by heidar yousef , Analyst Programmer & Team Leader , Municipality of Qatif Municipality - Eastern Region

SELECT column_name 

FROM tablename

GROUP BY column_name 

HAVING COUNT(column_name ) > 1

select name, count(sal) from users group by sal having(count(sal) >1)

Samuel Bolaji
by Samuel Bolaji , Oracle DBA , Mahindra Comviva

select column1, column2..., count(columnlast)

from table_name

where (all_conditions_if_required)

group by columnlast ------ (if it is the comlumn with duplicate data)

having count(columnlast) > 1 ;

Nidhi Goel
by Nidhi Goel , IOT Lead : Smart Meters , DEWA

In order to find the duplicate data from the table you can use the below query.

select empno,ename,sal,job,dept from employee

group by empno,ename,sal,job,dept from employee having count(1) > 1.

 

We have other methods also using analytical function, but this is easiest u can use.

Muslim Sattarov
by Muslim Sattarov , Academic Writer , Livingston Research

You can use HAVING keyword along with GROUP BY. For example,

SELECT *

FROM tablename

GROUP BY fieldname1

HAVING COUNT(fieldname1) > 1

fieldname1 is the name of the column that contain duplicate values. 

Indlamuri  Hari Krishna
by Indlamuri Hari Krishna , DataBase Developer , kolla Soft pvt. ltd

select distinct * from employee;

 

MEHRAN UDDIN
by MEHRAN UDDIN , Intern , Testing Campus InfoTech

select * from Employee group by empno,ename, sal, job, deptno having count(*)>1;

Jeethu George
by Jeethu George , Team Lead , IBM Pvt Ltd

select * from employee where rowid not in (select min(rowid) from emloyee group by empno);

MEERAN MOHIDEEN
by MEERAN MOHIDEEN , Software Engineer , C-Square Info Solutions Pvt Ltd

 SELECT ROWID,empno,ename,sal,job,deptno

   FROM employee mq

  WHERE mq.ROWID > ANY( SELECT csq.ROWID

                       FROM employee csq

                      WHERE csq.empno = mq.empno

                        AND csq.ename = mq.ename

                        AND csq.sal   = mq.sal

                        AND csq.job   = mq.job

                        AND csq.deptno = mq.deptno );

 

select EMPNO, ENAME, SAL, JOB, DEPTNO from employee group by EMPNO, ENAME, SAL, JOB, DEPTNO having count(*)>=2;

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.