ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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
تم إضافة السؤال من قبل Balaji Prakash , Data Analyst , Systech Solutions
تاريخ النشر: 2017/05/01
Rupesh Kumar
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل Indlamuri Hari Krishna , DataBase Developer , kolla Soft pvt. ltd

select distinct * from employee;

 

MEHRAN UDDIN
من قبل MEHRAN UDDIN , Intern , Testing Campus InfoTech

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

Jeethu George
من قبل Jeethu George , Team Lead , IBM Pvt Ltd

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

MEERAN MOHIDEEN
من قبل 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;

المزيد من الأسئلة المماثلة