I’m using SQL Server 2017 Microsoft SQL Server 2017 (RTM-GDR) (KB4583456) – 14.0.2037.2 (X64) Nov 2 2020 19:19:59 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 19042: ). I’m trying to sort the results of the STRING_AGG function. This works fine This gives me the error “Msg 102, Level 15, State 1, Line 1
Tag: string-agg
How to compare multiple rows
I have a table with data like following, want to return those group_id with unique data. Both group_id 3 and 4 have two component 123 and 456, so they are “duplicated”, we just need to return the smaller group_id, that’s 3. Also group_id 5 doesn’t have a duplication, it can be returned. So we want group_id 3 and 5 to
SQL query GROUP BY groups
I have something like this: id name totalAmount 1 name1 10 2 name1 20 3 name1 25 4 name2 5 5 name2 12 And need to looks like this: id’s name totalAmount 1,2 name1 30 2,3 name1 45 1,3 name1 35 1,2,3 name1 55 4,5 name2 17 I’m using the STRING_AGG but don’t know how to separated in the first
More than one row returned by a subquery when using STRING_AGG function
I get an error when trying to execute SELECT query in PostgreSQL 11 And authors_string should be fetched as a string value. It throwns an error ERROR: more than one row returned by a subquery used as an expression I guess it happens because of GROUP BY in subquery and can be handled with row_to_json function, but have no clue
SQL – Postgres string agg is giving duplicates
Im trying to collect the foreign key mapping from system tables. And I used this below query. query 1: But this won’t provide the Primary tables columns that are pointing as Fk. So I found this query on Stackoverflow. query 2 Now this query gives individual columns. Lets say there is a FK like (logid, item) then I’ll get two
Reverse to STRING_AGG
Here is a sample data on which we are further processing. My question is, is there any exact reverse of the STRING_AGG function for SQL Server? Like I am merging using STRING_AGG with the following code I need to reverse the process but I had to use CURSOR so I am searching for an alternative solution. Below is the cursor
SQL Server Concatenate three different columns into a Comma-Separated without repeated values
The next table is a simplification of my problem in SQL Server: I want to get a group with the columns concatenated by comma without repeated values. I tried to use STRING_AGG() but it returns: This is the query I have done: I would like the next result: Thank you! Answer Without using window functions. The union might slow things