Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Query to group the values based on the key column

I have a table called SOURCE_CATEGORY with SOURCEID and NAME. I have 4020 and 4025, how is it possible to combine the NAME field based on the SOURCEID using SQL Query?

enter image description here

I am hoping to get this result, because I wanted to copy the data in MSSQL to MongoDB which can combine the result into array. I only wanted the NAME field in mongodb. Is it possible to custom the SQL in MSSQL to kind of group them?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

You can do it using string_agg as follows :

select sourceid, string_agg( experience, ',') AS NAME
from source_category
group by sourceid
order by sourceid
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading