how to retrieve only duplicate values in a table
Answers were Sorted based on User's Feedback
Answer / ravi patel
for the table emp
ID NAME
1 ravi
2 umang
1 ravi
3 nishant
now fire the query as beleow
select * from emp group by id,name having count(id)>1 and
count(name)>1;
| Is This Answer Correct ? | 3 Yes | 0 No |
For example,u have a table called student like below.
STUD-NAME SUBJECT
--------- ------
STUD1 A
STUD2 B
STUD2 A
STUD1 A
in this structure 1 row is duplicated in 4 th. so we can
fetch the student name using the below qry.
SELECT stud-name FROM STUDENT
GROUP BY stud-name,subject
HAVING COUNT > 1.
| Is This Answer Correct ? | 12 Yes | 10 No |
Answer / p.rajasekar
select count(<Duplicate_FieldName>),fees
from Table Name
group by <Duplcate_FieldName>
having count(<Duplicate_FieldName>)>1
Regards
P.Rajasekar
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / sixface
ID NAME
1 ravi
2 umang
1 ravi
3 nishant
SELECT id,name
FROM emp
WHERE id in
(
SELECT id
FROM emp
GROUP BY id
HAVING COUNT(*) > 1
);
It gives all duplicate rows........
Lets try.....
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / suresh babu
select
id,
name
from
(select
id,
name
from
find_dup
group by
id,
name
having
count(*) > 1);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / siva
Select* from emp where rowid not in(select max(rowid) from emp group by empno);
| Is This Answer Correct ? | 0 Yes | 0 No |
select count (column_name),column_name from table_name group by column_name having count(column_name)>1;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / kirankumar.vangeti
For the same example given in the answer 1
select studentname, subject, count(studentname) as count
from student
group by studentname, subject
having (count(studentname)>1);
above query will give the results like
STUD1 A 2
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / akki julak
FOR EXAMPLE WE HAD TAKE EMP TABLE AND ENAME,EMPNO AS COLUMNS
SELECT EMPNO,ENAME
FROM EMP
WHERE ROWID NOT IN(SELECT MAX(ROWID) FROM EMP
GROUP BY EMPNO,ENAME);
by
AKKI JULAKANTI
| Is This Answer Correct ? | 1 Yes | 3 No |
What is the difference between the conventional and direct path loads? : aql loader
one of the column in my table contains the data like SAL ---- 1000 1000 2000 3000 3000 So my requirement is i want output like SAL --- 1000 2000 3000 it mean i want to delete duplicate rows only how should u write query?
Do we need commit after truncate?
What is meant by <> in sql?
Are stored procedures faster than queries?
What is compilation error in pl sql?
Why join is faster than subquery?
What are local and global Indexes and where they are useful.
How do I find duplicates in two columns?
What are the ddl commands?
Is sql better than excel?
Why do we use view in sql?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)