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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:40:28+00:00 2026-05-22T22:40:28+00:00

I have a table Managers . Columns: ManagerId, ManagerName . I have a table

  • 0

I have a table Managers. Columns: ManagerId, ManagerName.

I have a table Clients. Columns: ClientId, ManagerId, ClientName, ClientAddress, Details.

Each (every?) manager have clients in clients table.

I need a query that returns next table. Columns: Column1, Column2.

Column1: ManagerName

Column2: ClientName1 ',' ClientAddress1 ',' Details1 ';' ClientName2 ',' ClientAddress2 ',' Details2 ';' etc

In column2 just a list of clients which correspond to manager from column1.

How can I do that?

I guess I need to use COALESCE but I’m not sure.

  • 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-22T22:40:28+00:00Added an answer on May 22, 2026 at 10:40 pm

    Here is a working example using XML AUTO

    With Managers AS
    (
          Select 1 as ManagerId, 'Tom' as ManagerName
    UNION Select 2 as ManagerId, 'Jane' as ManagerName
    ),
    Clients as
    (
          Select 1 as ClientId, 1 as ManagerId, 'TaXon Pro' as ClientName, '112 Acme St Cityville DD 56' as ClientAddress, 'ABC' as Details
    UNION Select 2 as ClientId, 1 as ManagerId, 'Pro Xon' as ClientName, '12342 Bylo Rd Streetville DD 156' as ClientAddress, 'CDR' as Details
    UNION Select 3 as ClientId, 1 as ManagerId, 'Clean Svc' as ClientName, '6512 Toni St Townville DD 1236' as ClientAddress, 'D@#$' as Details
    UNION Select 4 as ClientId, 2 as ManagerId, 'ContraRel' as ClientName, '152 Acme St Villageville DD 3456' as ClientAddress, 'SER' as Details
    UNION Select 5 as ClientId, 2 as ManagerId, 'RepoIn' as ClientName, '1 Acme St Districtville DD 1456' as ClientAddress, 'KH' as Details
    )
    SELECT 
        M.ManagerName,
        (
            SELECT c.ClientName + ', ' + C.ClientAddress + ', ' + c.Details + ';'
            FROM Clients C
            WHERE m.ManagerId = c.ManagerId
            FOR XML PATH('') 
        ) AS Clients
    FROM Managers M
    GROUP BY 
        m.ManagerId, M.ManagerName
    

    The output will look like this

    ManagerName Clients
    ----------- -------------------------------------------------------------------------------------------------------------------------------------------
    Tom         TaXon Pro, 112 Acme St Cityville DD 56, ABC;Pro Xon, 12342 Bylo Rd Streetville DD 156, CDR;Clean Svc, 6512 Toni St Townville DD 1236, D@#$;
    Jane        ContraRel, 152 Acme St Villageville DD 3456, SER;RepoIn, 1 Acme St Districtville DD 1456, KH;
    
    (2 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

need some your help with a query. I have a table Managers (ManagerId, ManagerName)
I have a user profile table with columns User Name , Manager and many
I have a table with columns EmployeeID, EmployeeName, and ManagerID. ManagerID is a recursive
I have users table. There are three other tables: developers, managers, testers. All of
I have table with 50 entries (users with such details like Name Surname Location
I have table with 3 columns A B C. I want to select *
I have table in data base name train delay, with columns train number(int), DelayTime(int),
I have a table in my database containing football results, the relevant columns being
Assuming I have an employee table with 2 columns only: employee_id manager_id All employees
I have a table in an access db with columns for job description, project,

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.