danatel
danatel

Reputation: 4982

concatenate string in sql

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?

Upvotes: 0

Views: 1436

Answers (1)

RichardTheKiwi
RichardTheKiwi

Reputation: 107806

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.

Upvotes: 2

Related Questions