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

  • Home
  • SEARCH
  • 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 3961238
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:57:05+00:00 2026-05-20T02:57:05+00:00

Trying to find duplicate users by email, who have an item count less than

  • 0

Trying to find duplicate users by email, who have an item count less than 0. I’ve got the duplicate users working (though it returns the full list of users sorted, instead of a subset):

select users.id, email, count(email) as count
from users
group by users.email
order by count desc

I’m trying to join on Items where count(items.id) < 1, but that doesn’t seem to work.

select users.id, email, count(email) as count
from users
join items on items.user_id = users.id
having count(items.id) < 1
group by users.email
order by count desc

I also tried an IN query, but can’t seem to get the syntax right.

Easy way to do this? Thanks!

UPDATE:

This query did the trick:

    select DISTINCT(u1.id), u1.email
    from users u1
    inner join users u2
        on 1=1
        and u1.email = u2.email
        and u1.id != u2.id
    where not exists (select * from items i where i.user_id = u1.id)
    order by u1.id
  • 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-20T02:57:05+00:00Added an answer on May 20, 2026 at 2:57 am

    Duplicated users:

    select 
        email, 
        count(*) as count,
        min(id) first_user_with_this_email_id
    from users
    group by email
    having count(*) > 1
    

    For second one, try this:

    select 
        users.email, 
        count(*) as count
    from users
    left join items 
    on (items.user_id = users.id)
    where items.id is null --there are no related items
    group by users.email
    having count(*) > 1 --there are at least two users
    

    Another version of second:

    select 
        u.email, 
        count(*) as count
    from users u
    where not exists (select * from items i where i.user_id = u.id)
    group by u.email
    having count(*) > 1 --there are at least two users
    

    Make sure you have index on user_id in items table.

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

Sidebar

Related Questions

I am trying to find duplicate rows in my DB, like this: SELECT email,
Trying to find the sqlserver adapter for rails on windows. I have tried getting
Been trying to find a working implementation of a WPF listview (or listbox) where
So I'm working with authlogic, and I'm trying to duplicate the login functionality to
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
Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Javascript: find the time left in a setTimeout()? I'm trying to use
I'm trying find a way to create mysql users with passwords using php code,

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.