Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:51:39+00:00 2026-05-16T11:51:39+00:00

I am trying to find duplicate rows in my DB, like this: SELECT email,

  • 0

I am trying to find duplicate rows in my DB, like this:

SELECT email, COUNT(emailid) AS NumOccurrences 
FROM   users 
GROUP BY emailid HAVING ( COUNT(emailid) > 1 )

This returns the emailid and the number of matches found. Now what I want do is compare the ID column to another table I have and set a column there with the count.

The other table has a column named duplicates, which should contain the amount of duplicates from the select. So let’s say we have 3 rows with the same emailid. The duplicates column has a “3” in all 3 rows. What I want is a “2” in the first 2 and nothing or 0 in the last of the 3 matching ID rows.

Is this possible?

Update:

I managed to have a temporary table now, which looks like this:

mailid | rowcount | AmountOfDups
643921 | 1 | 3
643921 | 2 | 3
643921 | 3 | 3

Now, how could I decide that only the first 2 should be updated (by mailid) in the other table? The other table has mailid as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:51:39+00:00Added an answer on May 16, 2026 at 11:51 am
    SELECT ...
           ROW_NUMBER() OVER (PARTITION BY email ORDER BY emailid DESC) AS RN
    FROM ...
    

    …is a great starting point for such a problem. Never underestimate the power of ROW_NUMBER()!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find duplicate users by email, who have an item count less than
So this is what I am trying to do: select subscriber, count(subscriber) from subscribers
I'm trying to find duplicate rows based on mixed columns. This is an example
I'm trying to find duplicate customers in a table that looks like this: customer_id
I am trying to find rows that have duplicate values, but only based off
I'm trying to find a way to duplicate a series of files/folders from one
I am trying to find a way to prevent users from double-submitting my forms.
I'm trying to find duplicate keys so that they can be addressed and made
i am trying to create sql procedure or function that need to find duplicate
Possible Duplicate: Comparing Two Arrays Using Perl I am trying to find elements that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.