Questions tagged [string-aggregation]

This tag is intended for SQL questions where multiple string (character) values should be aggregated into a single value using GROUP BY. The equivalent of sum() - just for strings.

The ISO/IEC SQL standard function for this is LISTAGG, but several DBMS:es have their own string aggregation functions:

386 questions
1
vote
1 answer

Inner Join and Group Multiple Tables into one row

I am using MSSQL Server and I would like to INNER JOIN and GROUP the data from multiple tables. But i got this error: Column 'MyDB.dbo.USER.EmployeeID' is invalid in the select list because it is not contained in either an aggregate function or the…
1
vote
1 answer

Concatenate many rows into comma-separated list based on unique id

I'm new to SQL (running SQL Server 2012), the query I'm running is returning these results. IDNum Email ---------------- 1 a@a.com 1 b@b.com 1 c@c.com 2 d@d.com 2 e@e.com 3 f@f.com 3 g@g.com 3 …
Gary N
  • 15
  • 4
1
vote
2 answers

string_agg: more than two attributes concatenation

I am using postgresql 9.0 I am wonder if its possible to concatenate three attributes together. this is how I concatenate two attributes (book & the comma): SELECT string_agg(book, ',') FROM authors where id = 1; |…
tokhi
  • 21,044
  • 23
  • 95
  • 105
1
vote
1 answer

Group by or concatenate multiple columns by multiple criteria

I need to do what I thought was going to be a simple SQL query.. but I got stuck deciding how can these be grouped:

I've got the below table:

Company | Airport | Type ------------------------------------------ SP1 |…
1
vote
1 answer

postgres aggregate not showing rows where LEFT JOIN table has nulls

I have a table that list email addressed for a member and has a boolean is_selected. The idea is that only one should be selected. I am joining the table to itself with a where clause on is_selected. I want to string_agg(u.email, ',') to show all…
gooddadmike
  • 2,329
  • 4
  • 26
  • 48
1
vote
2 answers

Oracle string aggregation

My table structure look like this, I am new for the this field. I know the basic queries.But it's complicated for me. Please help me to do this. Table structure Customer Product piriority 10001 Main_product 1 …
Milton
  • 171
  • 1
  • 4
  • 15
1
vote
1 answer

Oracle SQL group by queries, Kind of PIVOT

Till now i haven't got a need to post a query, almost everything is available. This is my first question. I have a different requirement, I have the below table name say…
1
vote
1 answer

Output a comma-separated list in a column in SQL Server

Possible Duplicate: Simulating group_concat MySQL function in SQL Server 2005? What's the best way to achieve this? Edit: in MSSQL 2005 Table a | b ------------ x | 1 x | 4 y | 6 y | 1 Query: SELECT ? FROM Table so that output…
beauk
  • 178
  • 3
  • 16
1
vote
2 answers

Join multiple rows into a string

I have 2 tables in Oracle: table1 and table2 (we have a very unimaginative DBA!) table1 has column id (and a few others). table2 has columns id, table1id and code. table1id is a foreign key to table1. Usually there is 1 table2 row for each table1…
CompanyDroneFromSector7G
  • 4,291
  • 13
  • 54
  • 97
0
votes
3 answers

Oracle/SQL - Multiple Records Into One [string aggregation]

I realize this is a ridiculous request, but what I'm trying to do is pull multiple records back into a single column along with some literal text. So given a table like this REGION CITY SID ------------------- 1 Chicago 1234 1 Palatine…
dscl
  • 1,616
  • 7
  • 28
  • 48
0
votes
4 answers

SELECT returning multiple rows as string

I have a table: Contracts: contractid | contract name "1" | "MAG:001" "2" | "MAG:002" -- and -- Devices: devid | serialnum | fk_contractid 10 | 1234 | 1 11 | 5678 | 1 12 | 4321 | 2 13 | 8765 | 2 devices.fk_contractid = contracts.contractid I need…
dakt
  • 620
  • 1
  • 9
  • 24
0
votes
1 answer

Aggregate columns but distinct terms should be inserted

I have two table and I want to merge them TERMS_TABLE ID | TERMS 309 | 'hardware' 309 | 'software' 309 | 'computer' TFIDF_TABLE ID | TERMS 309 |'computer,phone,mp3....' Now I want to add TERMS column of TERMS_TABLE to terms column of…
user951487
  • 845
  • 7
  • 19
  • 30
0
votes
0 answers

Question marks appearing in query result when I concatenate values from multiple rows

I am trying to concatenate values in a column when those values correspond to the same ID number. Here's an example of the data: The query result I want is this: Here is the code I tried to achieve this result. SELECT column1, …
0
votes
1 answer

SQL - Pivot Column To Rows with Group By and Concat

I need to traspose a column into a row ( by concatenating it) with group by... using : sql server…
Enrico
  • 75
  • 1
  • 11
0
votes
2 answers

Is it possible to use three LISTAGGs and group by elements in row?

I have a situation where I would like to put three different columns, each which have multiple rows, into a single row. I am using this code, which works to give me all of the first columns, then the second columns, then the third. , '('…
Aaron
  • 51
  • 6