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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:29:14+00:00 2026-05-27T15:29:14+00:00

I need to get the distinct rows based on a single column (code in

  • 0

I need to get the distinct rows based on a single column (code in this case) where there are duplicates of that column value. Along with other information from the row and the number of duplicate rows there are. for example:

ID     code     ownerName
--------------------------
1      001      Mr. Brown
2      001      Mr. Pink
3      002      Mr. White
4      003      Mr. Blonde

I need this query to return

ID     code     ownerName    count
----------------------------------
1      001      Mr. Brown      2

the duplicate row information does not matter which gets returned, but I’m having trouble combining the distinct codes with the count column.

I’ve tried a query like this:

SELECT DISTINCT A.code, A.ownerName 
FROM Customers A WHERE 
   EXISTS( SELECT * FROM Customers WHERE code = A.code AND id <> A.id) 
order by A.code;

but I’m having trouble getting the count; and with this query

SELECT code, COUNT(*) as numberDuplicates 
FROM Customers GROUP BY code HAVING COUNT(*) > 1

I’m having trouble getting other information I don’t want to group by. Can anyone help me figure out how to structure the correct query?

  • 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-27T15:29:15+00:00Added an answer on May 27, 2026 at 3:29 pm

    If I understand what you are looking for, this should work:

    This will select all entries with a non-unique code and return the number of records using that code.

    SELECT DISTINCT A.ID, A.Code, A.ownerName, B.Count
    FROM Customers A
    JOIN (
      SELECT COUNT(*) as Count, B.Code
      FROM Customers B
      GROUP BY B.Code
    ) AS B ON A.Code = B.Code
    WHERE B.Count > 1
    ORDER by A.Code;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get a set of distinct records for a table along with
I'm struggling with a query where I need to SUM DISTINCT Rows. There has
I need to get a get a count of all the distinct subnets in
I have two tables with a weak relation. I need get a text value
I have a statement that SELECTs distinct rows from a table with a two
Greetings, Here is my problem. I need to get data from multiple rows and
I have a few tables that I need to link together to get a
I have a table that looks something like this: ________________________ |id|value|date|approved| ----------------------- What I
I have created this function GetSubName that I need to return the name that
This is my base query select distinct a.projects , case when(billing_fy!=0) then(select round(((sum(cost_project)/(sum(billing_fy)/((10/12)*365)))),2) from

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.