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 6597677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:14:22+00:00 2026-05-25T18:14:22+00:00

I have a table entries with three columns: id, name, display_name . I need

  • 0

I have a table entries with three columns: id, name, display_name.
I need to write a query with join, which will check how many display_names there is for each name and display only those names, which have multiple display_names.
This should be fairly simple to write with joins. Before I used next query:

SELECT e1.name 
FROM entries e1 
WHERE (
  SELECT COUNT(DISTINCT e2.display_name) 
  FROM entries e2 
  WHERE e2.name = r1.name
) > 1;
  • 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-25T18:14:22+00:00Added an answer on May 25, 2026 at 6:14 pm

    You don’t need a join.

    SELECT e1.name 
    FROM entries e1 
    GROUP BY e1.name
    HAVING COUNT(*) > 1
    

    Note that you can use an alias in a having clause, so borrowing from @Scorpi0 and @Widor you can also do:

    SELECT e1.name, COUNT(DISTINCT e1.display_name) as occurrences
    FROM entries e1 
    GROUP BY e1.name
    HAVING occurrences > 1
    

    The reason this is allowed is that having is evaluated after all the other stuff in the select is done. By that time the contents of the alias will be known.
    You cannot use this alias in the WHERE clause because that runs (or may run) before MySQL knows what in the alias.

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

Sidebar

Related Questions

I have a table y Which has two columns a and b Entries are:
I have a table of transactions which will occasionally have duplicate entries. If/When an
Suppose I have a table called 'test', into which there are three columns named
I have a MySQL table which has three columns: Authority | MapID | Time
I have table with 50 entries (users with such details like Name Surname Location
I have a table story_category in my database with corrupt entries. The next query
I have a MySQL table that holds many entries with repeated IDs (for various
I have a table with three columns: taxon_id , scientific_name_element_id , and parent_id .
Ok... I have a database table called employees.. This has columns called ID, Name,
I have a table in MySQL with 30 columns and thousands of entries. Is

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.