what is the sql query to find the duplicate records and display in descending, based on the highest count and the id display the records.
for example:
getting the count can be done with
select title, count(title) as cnt from kmovies group by title order by cnt desc
and the result will be like
title cnt
ravi 10
prabhu 9
srinu 6
now what is the query to get the result like below:
ravi
ravi
ravi
...10 times
prabhu
prabhu..9 times
srinu
srinu...6 times
You can do it in a single query:
This query uses the
Group By
and andHaving
clauses to allow you to select (locate and list out) for each duplicate record. TheAs
clause is a convenience to refer toQuantity
in theselect
andOrder By
clauses, but is not really part of getting you the duplicate rows.If your RDBMS supports the OVER clause...
You can't do it as a simple single query, but this would do: