0

I have data in my table as following:

Author ID  Book Name

A1    Book1

A1    Book2

A2    Book4

A2    Book5

I want to represent the data as

A1  Book1,Book2

A2  Book3,Book5

How I can do that without using a temporary table?

Arun Bertil
  • 4,598
  • 4
  • 33
  • 59
user1672097
  • 361
  • 1
  • 4
  • 12

1 Answers1

0

This question is already asked and answered.Check the questions before you post.

Edit this code according to your column.

Reference

   Select T1.Id
    , Stuff(
        (
        Select ', ' + T2.Address
        From MyTable As T2
        Where T2.Id = T1.Id
        Order By T2.Address
        For Xml Path(''), type
        ).value('.', 'nvarchar(max)'), 1, 2, '') As Address
From MyTable As T1
Group By T1.Id
Community
  • 1
  • 1
Sasidharan
  • 3,676
  • 3
  • 19
  • 37
  • 1
    Please flag questions as duplicates, and don't just re-post the answer. This question will be closed as a duplicate soon. – DaveShaw Aug 30 '13 at 10:51