COUNT DUPLICATE RECORDS IN MYSQL -


i need query count duplicate records,

for example

table name -customer ===================  customer_id-col name 222 111 222 222 111 122 

output be

customer_id   count  222              3 111              2 222              3 222              3 111              2 122              1  

i tried query

select customer_id,count( customer_id ) c customer group customer_id having c >1

output is

customer_id count

222              3 111              2 122              1  

is possible in advance

thanks raja

try this

select t.customer_id,s.duplicate_count     (     select customer_id,count(customer_id) duplicate_count     yourtable group customer_id     having (duplicate_count > 0)     ) s join yourtable on s.customer_id = t.customer_id 

fiddle demo

op:

  customer_id       count      222              3     111              2     222              3     222              3     111              2     122              1   

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

angularjs - ng-repeat duplicating items after page reload -