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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:34:46+00:00 2026-06-17T14:34:46+00:00

Suppose the schema is like this: First Name | Last Name | Age |

  • 0

Suppose the schema is like this:

First Name | Last Name | Age | ID
====================================
John         Smith       18    123
John         Smith       21    234
John         Smith       19    123
Cathy        Zhang       20    144
Cathy        Zhang       20    144
Jackie       Chan        35    456

Suppose I want to count the number of distinct pairs after each (first name, last name). So that the output should be:

John         Smith       3
Cathy        Zhang       1
Jackie       Chan        1

I think I can first do:

SELECT FirstName,LastName,Age,ID,COUNT(*);

And then

SELECT FirstName,LastName,COUNT(*)

Is there a better approach?

  • 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-06-17T14:34:47+00:00Added an answer on June 17, 2026 at 2:34 pm

    To return the count of each distinct firstname lastname, you would use COUNT and GROUP BY:

    SELECT FirstName, LastName, COUNT(*)
    FROM TableName
    GROUP BY FirstName, LastName
    

    In your above example, I think you meant Zhang to have a count of 2 though.

    –EDIT

    If I’m understanding your latest comment correctly, you want to also use DISTINCT:

    SELECT FirstName, LastName, Age, Id, COUNT(*)
    FROM (SELECT DISTINCT FirstName, LastName, Age, Id FROM TableName) T
    GROUP BY FirstName, LastName, Age, Id
    

    Good luck.

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

Sidebar

Related Questions

Let's suppose I have a schema like this: var Person = new Schema({ name:
Suppose I have the following schema t = {name: 'John', reviews: [{sid: 1, comment:
Suppose I have this (outrageously) simplified XML schema: <xsd:complexType name=Person> <xsd:sequence> <xsd:element ref=FirstName/> <xsd:element
Suppose we have a NAME table like this: PERSON_ID PART_TYPE VALUE and PERSON_ID is
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose i have one table that holds Blogs. The schema looks like : ID
Suppose I have a Dictionary<string, string> instance, like this one: { { a, 1
I have a BizTalk schema that looks something like this: <Root> <Header> <SomeData></SomeData> <Detail>
Suppose i have this db table schema: id | article | slug 1 hey
This is my first try trying to use WCF, so I'm guessing I'm doing

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.