1

I'm trying to join all results from one column in SELECT query into one string.

Some of you might be familiar with C#:

string.Join(separator, stringArray)

The following statement doesn't return all results as one string

SELECT CONCAT(text) FROM orders

Does anyone have an idea of how to replicate that C# code by means of SQL?

1 Answer 1

2

You are looking for string_agg():

select string_agg(text separator, ',')
from orders;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer! Gave me the chance to google PostgreSQL equivalent - string_agg(DISTINCT text, ', '). Works like a charm!
@a_horse_with_no_name . . . Clearly, I was confused.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.