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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:49:12+00:00 2026-06-12T05:49:12+00:00

I have a SQL question, and hope someone could help me or give me

  • 0

I have a SQL question, and hope someone could help me or give me some pointers. Much appreciated.

I have two tables: A and B.

  • A has columns ID which is the primary key field, and NAME
  • B has columns DUPID, NAME and ID which is the primary key

The relationship between A and B is in B, the DUPID contains certain values of A.ID, and the request is to append distinct B.NAME value to A.NAME separated by semi-colon based on join A.ID = B.DUPID..

Maybe my explanation isn’t clear, here is a simple example.

A                                  B
ID  NAME                           DUPID      NAME
1   null                            1             John
2   null                            1             John
3   null                            1             Mark
4   null                            3             Luke
5   null                            3             Luke
                                    3             Luke
                                    3             Matthew

So eventually, I will need to update table A, and make it look like below

A
ID      NAME
1        John;Mark
2        null
3        Luke;Matthew
4        null
5        null
  • 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-12T05:49:13+00:00Added an answer on June 12, 2026 at 5:49 am

    Unlike MySQL, SQL Server doesn’t have a built-in function to do that. But you can still simulate it by using CROSS APPLY and FOR XML PATH('')

    SELECT  a.ID, 
            SUBSTRING(d.NameList,1, LEN(d.NameList) - 1) Names
    FROM    a
            CROSS APPLY
            (
                SELECT DISTINCT [NAME] + '; ' 
                FROM  B 
                WHERE A.ID = B.DupID 
                FOR XML PATH('')
            ) D (NameList) 
    

    SQLFiddle Demo

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

Sidebar

Related Questions

I have an SQL question which may be basic to some but is confusing
I have a small sql question for you. I have two queries: SELECT tbl_CostPrevisions.Month,
I have quick question for you SQL gurus. I have existing tables without primary
I've done some searching around but I have a specific question on SQL Injection
my SQL skills aren't strong enough to figure this out, hope someone can help.
Hello all I have a question I hope you guys can help me with.
I have an Oracle question, hope someone can guide me. I am using php
I have two sql tables called scan_sc and rescan_rsc . The scan table looks
Here's a tricky normalization/SQL/Database Design question that has been puzzling us. I hope I
I have a SQL question that i need to ask the experts. To be

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.