0

I have a database table "create table t (s varchar, i int)" with 100 records.

When I want to sum all 'i' fields, I invoke something like "select sum(i) from t". Is there a way to concatenate the 's' fields? (select concatenate(s) from t)

In any sql dialect?

2
  • as a oneliner? Or are 'procedural' solutions also permitted? Commented Feb 15, 2011 at 17:29
  • 1
    possible duplicate of SQL Server 2008 - Concatenate String Commented Feb 15, 2011 at 17:30

1 Answer 1

2

In any sql dialect?

There isn't an ANSI SQL specified way to do this across all SQL dialects. If you want specific solutions for a particular DBMS, then sure, some have a ready made solution, and others have generalized solutions that are more complicated.

e.g.

  • Oracle = WM_CONCAT
  • MySQL = GROUP_CONCAT
  • SQL Server = UDF / FOR XML PATH('') / recursive CTE

You need a question for each RDBMS you need the solution for, but you will find duplicate questions for each case already on StackOverflow.

Sign up to request clarification or add additional context in comments.

Comments

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.