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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:14:48+00:00 2026-05-15T20:14:48+00:00

I have 3 tables: User (PK userid, …) Computer (PK computerid, FK userid, FK

  • 0

I have 3 tables:

User (PK userid, ...)  
Computer (PK computerid, FK userid, FK cpuid, ...)   
CPU (PK cpuid, ...)

So, a user can have multiple computers, and each computer has exactly one CPU. Same cpu can appear in different computers.

I would like to get the number of computers and unique CPUs per user.

userid | Number of computers | Number of CPUs
---------------------------------------------
     1 | 3                   | 1     <- has 3 comps all with the same cpu
     2 | 13                  | 4     <- has 13 comps with 4 different cpus
...and so on

I dont have the problem with counting computers, but I stuck on counting the CPUs. Joining tables causes bad results because if the same cpu appears in more then one computer – count() returns total number of records as if they were not grouped…

  • 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-15T20:14:49+00:00Added an answer on May 15, 2026 at 8:14 pm

    You don’t need a join, because you can count the IDs instead of using COUNT(*). In this case, your query would be:

    SELECT userid, COUNT(DISTINCT computerid) AS Computers, COUNT(DISTINCT cpuid) AS CPUs
    FROM Computer
    GROUP BY userid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, in which one user can have several contacts: User(UserId, UserName)
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have a table User which has an identity column UserID , now what
I have a table that stores user information. The table has a userid (identity)
I have a table UserAliases ( UserId, Alias ) with multiple aliases per user.
i have 2 tables called user, with the fileds user.userID and user.lastActivityTime, and session
I have 2 tables, 'interests' and 'users_interests'. 'users_interests' just has userid and interestid fields.
I have the following database tables: Table1: User UserId Username Table2: Role RoleId Rolename
Im modelling a database in MSSQL 2008. I have 4 tables. **User** userID userName
I have 3 tables MySQL (MyIsam): user (id), message (id, userId, ...), archivedMessage (id,

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.