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

  • Home
  • SEARCH
  • 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 4325266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:14:36+00:00 2026-05-21T09:14:36+00:00

need your help with GROUP BY clause. I have two tables: Managers and Clients

  • 0

need your help with GROUP BY clause.

I have two tables: Managers and Clients (I simplified it for a question).

Managers:
managerId int PK,
ManagerName nvarchar(50)

and

Clients:
ClientId int,
ClientName nvarchar(50),
ManagerId int, WhenAdded datetime

I store managers list in Managers table. Each client from Clients table has a corresponding manager.

I want a sql query which returns following table:

ManagerName nvarchar(50),
NumberOfClients int

My problem is:
if manager doesn’t have a client(s). Sql query doesn’t include ManagerName in resulting table.

I tried this query:

SELECT M.ManagerName, COUNT(*) 
FROM
Clients AS C left join Managers AS M 
ON
C.ManagerId = M.ManagerId
GROUP BY 
M.ManagerName

Second question

Same as a first question, but if I want to add a where clause to the WhenAdded field in Clients). Query must return ManagerName and NumberOfClients even if NumberOfClients=0.

  • 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-21T09:14:37+00:00Added an answer on May 21, 2026 at 9:14 am

    You can use this:

    SELECT ManagerName, (SELECT Count(ClientID) FROM Clients C WHERE
        C.ManagerID=M.ManagerID) As NumberOfClients FROM Managers M;
    

    or this:

    SELECT ManagerName, Count(C.ClientID) As NumberOfClients FROM Managers M
        LEFT JOIN Clients C ON M.ManagerID=C.ManagerID GROUP BY M.ManagerID,
        M.ManagerName;
    

    The problem with your query is that you’re using Clients table as basic table.

    For the second question you can use this:

    SELECT ManagerName, (SELECT Count(ClientID) FROM Clients C WHERE
        WhenAdded<DATEADD(day, 1, GETDATE()) AND M.ManagerID=C.ManagerID) As
        NumberOfClients FROM Managers M;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need your help, For example I have a decimal type variable and I
I've some questions .. and I really need your help. I have an application.
I have a problem here and need your help. I've been trying to capture
i've no idea how to do that and need your help! i have an
I had a recursion interview question problem in Java,Need your help on this. Write
We have a security problem here and we really need your help and inputs.
i need your help in access db i have a table like this ID
I need your help again. So I have a simple list <ul> <li>First</li> <ul
I need your help to define a special case in XML schema: A sequence
I really need your help in my issue very quickly and it's too close

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.