sql server - group records bases on one column name in data set and display all the values corresponding to the column for which records are grouped in SQL -


for example, if have data-set below

id item 1   2   b 3   c 1   b 1   c 2   

then need sql query gives output below:

id  item 1    a, b, c 2    b, 3    c 

that how group based on id , display values pertaining column attributes in sql.

replace table names table name , use below query:

select src.id,        src.items [items]             (             select distinct t2.id,                  (                     stuff((select t1.item + ',' [text()]                     [yourtable-name] t1                     t1.id = t2.id                     order t1.id                     xml path ('')),1,1,'')                 ) [items]             [yourtablename] t2         ) [src] 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -