Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

total number of duplicates in oracle table

I have a table like below

SUBJECT Years MARKS
AB      1       20
AB      1       25
AC      1       20
AC      1       30
AC      1       40
AD      1       20

I only need count of duplicates (subject||Year), expected answer is 2 and not

AB1 -- 2
AC1 -- 3
like image 370
user1627796 Avatar asked Jan 15 '23 17:01

user1627796


2 Answers

That would be one more query on top of the duplicates query...

select subject, year, count(*)
  from table1
  group by subject, year
  having count(*) > 1

will give you all the results with counts. Another count over this..

select count(*)
  from (
select subject, year, count(*)
  from table1
  group by subject, year
  having count(*) > 1
) 

should give you the number of records which have one or more duplicates.

like image 62
Rajesh Chamarthi Avatar answered Jan 28 '23 07:01

Rajesh Chamarthi


select subject,years, count(*)
from table
group by subject,years
having count (*) > 1;
like image 23
vikiiii Avatar answered Jan 28 '23 05:01

vikiiii