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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:01:14+00:00 2026-06-12T11:01:14+00:00

Given the following SQL tables (with data) create table a (key1 INT, value1 NVARCHAR(MAX))

  • 0

Given the following SQL tables (with data)

create table a (key1 INT, value1 NVARCHAR(MAX))
create table b (fk INT, value2 NVARCHAR(MAX))

INSERT INTO a(key1, value1) values (1, 'test1')
INSERT INTO a(key1, value1) values (2, 'test2')

INSERT INTO b(fk, value2) values (1, 'b1.1')
INSERT INTO b(fk, value2) values (1, 'b1.2')
INSERT INTO b(fk, value2) values (1, 'b1.3')

I would like to return the foreign key values in b concatenated together like so:

key1    value1  col
1       test1   b1.1, b1.2, b1.3
2       test2   NULL

I know it’s possible (theoretically) with FOR XML PATH, I just can’t figure it out

  • 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-12T11:01:15+00:00Added an answer on June 12, 2026 at 11:01 am

    This should get you the results you want:

    select a.key1,
      a.value1,
      stuff((select distinct ', ' + value2
             from b
             where a.key1 = b.fk 
             for XML path('')),1,1,'') 
    from a
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

Given the following data table definitions in SQLite Version 3.7.5: CREATE TABLE [Books] (
I have a SQL table: CREATE TABLE [UserTable] ( [ID] [int] NULL, [Name] [nvarchar](50)
Given the follwing: SQL Tables: Names ----- Id (int) FirstName (varchar) LastName (varchar) NameProperties
Given the following schema / data / output how would I format a SQL
Is there a proper term in data modeling to describe the following? Given table
I have a organization name table with the following structure given below: CREATE TABLE
The following query is given in a PL/SQL procedure . SELECT e.data FROM extra
I have a SQL Server table with the following structure: CREATE TABLE [dbo].[Log]( [LogID]
I have the following SQL query I was given, but I am not sure
Given the following HTML <b>demo</b> I want to save it to an SQL 2005

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.