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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:01:09+00:00 2026-05-18T03:01:09+00:00

In MS SQL Server 2008. How do I count the number of rows that

  • 0

In MS SQL Server 2008.
How do I count the number of rows that have a certain field in common.
Example, lets say I have the following table.

UserAccount_ID Attribute_ID
786            11
797            10
797            5
797            6
797            11
555            11
1003           10
1003           5
1003           6
1003           11
633            11
2036           11
2087           10
2087           5
2087           6
291            11

What query do I need to perform to get the following table. This will count the number of records with the same UserAccount_ID

UserAccount_ID Count
    786            1
    797            4
    555            1
    1003            4
    633            1
    2036            1
    2087            3
    291              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-18T03:01:10+00:00Added an answer on May 18, 2026 at 3:01 am
    create table #YourTable (
        UserAccount_ID int,
        Attribute_ID int
    )
    
    insert into #YourTable
        (UserAccount_ID, Attribute_ID)
        select 786,11 union all
        select 797,10 union all
        select 797,5 union all
        select 797,6 union all
        select 797,11 union all
        select 555,11 union all
        select 1003,10 union all
        select 1003,5 union all
        select 1003,6 union all
        select 1003,11 union all
        select 633,11 union all
        select 2036,11 union all
        select 2087,10 union all
        select 2087,5 union all
        select 2087,6 union all
        select 291,11
    
    select UserAccount_ID, count(*)
        from #YourTable
        group by UserAccount_ID
    
    drop table #YourTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does SQL Server 2008 ship with the .NET 3.5 CLR, so that stored procedures
Has anyone tried installing SQL Server 2008 Developer on a machine that already has
SQL Server 2008 has new geo data types. One thing I am wondering though
Is SQL Server 2008 a good option to use as an image store for
In SQL Server 2008 and given TableA(A_ID, A_Data) TableB(B_ID, B_Data) ViewC(A_or_B_ID, A_or_B_Data) is it
I'm using SQL Server 2008 with Advanced Services on my Vista Home Premium. I'd
I'm running SQL Server 2008 Express on Windows XP on a VirtualPC instance inside
Is the Sql Server 2008 control available for download? Does it yet support the
I installed SQL Server 2008 (SQL Server 2005 was already installed) on my XP
I need to purchase SQL Server 2008 Standard edition, because it's features fit what

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.