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
0 answers

SQL - using string_agg twice

I am trying to write two strings from selecting value from a column on multiple rows. I am getting a string back but the result is not correct, the string that is returned has repeated the specialism_name and qualification_name is being repeated as…
ynwebdev
  • 11
  • 4
1
vote
1 answer

SQL Server: Combine multiple rows into one row from a join table?

I have an SQL query that looks like this. SELECT ID, Data1, DataFromTable2 FROM Table1 LEFT JOIN Table2 on Table1.ID = Table2.ID WHERE ID = 1 I'm trying to join the two tables where Table2 (which contains multiple rows with the same ID). And I…
bigbryan
  • 411
  • 6
  • 19
  • 36
1
vote
2 answers

How to select values from many rows that has the same id to just one row and separate them with -?

i'd like to display the values of the table with the same id in just one row and separate them with - or, row id | base_id | auth_id --------+---------+--------- 4 | 1 | 1 5 | 1 | 3 6 | 2 | 2 …
1
vote
1 answer

How to delete duplicates after STRING_AGG?

First of all i've to tell you that i'm a beginner in SQL. I want to select all the informations related to my PLAN thanks to it's id to put them in a DataGridView in my C# program. We can affect multiples voltage levels, catenary types etc... to…
tsoich
  • 23
  • 1
  • 3
1
vote
2 answers

SQL: How to concatenate every group of N rows into a single row

I have this ID | Name ----+------- 31 | Abby 24 | Bruce 44 | Carl 49 | Derek 55 | Eric 81 | Fred I want to concatenate groups of N rows into a single row. For N = 3, this would give me this ID | Name…
Philippe
  • 245
  • 2
  • 12
1
vote
2 answers

can we make multiple rows as comma seperated in SQL Query?

can we make multiple rows as comma seperated in SQL Query? query should return something like: 1, "john,mike,petra" 2, "bob,carl,sandra,peter, etc
Febin J S
  • 1,358
  • 3
  • 26
  • 53
1
vote
1 answer

Group by PostgresSQL

I have the following result Student Form ID | Result ----------------------------- 12 | PASSED 131 | PASSED 131 | RESIT 144 | FAIL 23 | NA Ideally I want where the ID is the same…
1
vote
1 answer

SQL Server 2008. Take info from two tables and concatenate row values.

I have looked at what was marked as the duplicate of this and it is not. I'm pulling from two tables, not one. First, allow me to say I had nothing to do with the design of this database. I have two tables that must be joined, and then an unknown…
BethD
  • 13
  • 3
1
vote
1 answer

psql 9.1 ERROR: column must appear in the GROUP BY clause or be used in an aggregate function

I have 3 tables : summaries, segment, people. people Column | Type | ------------------+-----------------------------+ id | bigint | last_name |…
mamesaye
  • 2,033
  • 2
  • 32
  • 49
1
vote
1 answer

MS SQL Concatenate multiple values into a single column

I currently have the following table; Invoice Client Purchase Order 1000 A1 1234 1000 A1 1235 1001 B2 1236 1001 B2 1237 1002 B2 1238 and I'm looking for a quick way to get to; Invoice …
1
vote
0 answers

Sum string values to one column Oracle SQL

I'm using some SQL queries to extract data from a Oracle database, but one of the issues I keep having is duplicate rows because of unique data in each row. Example of this: TEST 01-11-17 global CURRENT 14-06-18 1474 AAXXZZ TEST …
Danny
  • 189
  • 2
  • 15
1
vote
2 answers

XML PATH SQL SERVER

I have data TIPE| NILAI PSX 10 GE 10 EG 10 SX 20 SXL 20 SZ 20 how to get output like psx/ge/eg = 10 sx/sxl/sz = 20 and this is my sytax ISNULL(CAST((SELECT CONVERT(VARCHAR,TIPE) + ' / ' FROM tabel FOR XML…
1
vote
1 answer

converting oracle's listagg to postgres

I am trying to convert some Oracle queries to Postgres and came across listagg. Oracle code select max(eta) eta, mso_id, listagg(carrier_name, ',') within group (order by eta) as carrier from tb_flight_schedule group by mso_id; I found out that…
coldhands
  • 327
  • 1
  • 3
  • 13
1
vote
3 answers

Convert LISTAGG to XMLAGG Oracle

I have a below SQL and I am trying to convert the LISTAGG to XMLAGG. My DB version is 12.1 and hence LISTAGG is not supporting more than 4K characters. Orignal Query :-- SELECT LISTAGG (se1.EMAIL, ', ') WITHIN GROUP (ORDER BY se1.EMAIL) AS…
Anand Abhay
  • 349
  • 1
  • 3
  • 10
1
vote
2 answers

LISTAGG equivalent for 10g

I'm on Oracle 10g and so unfortunately I can't use listagg (as this requires 11g). So I would like to port the code below to an alternative for 10g: select count(*) from ( select listagg(flag) within group (order by dt) as flags from …
Hey StackExchange
  • 2,057
  • 3
  • 19
  • 35