My table contains the details like with two fields:
ID DisplayName
1 Editor
1 Reviewer
7 EIC
7 Editor
7 Reviewer
7 Editor
19 EIC
19 Editor
19 Reviewer
I want get the unique details with DisplayName like
1 Editor,Reviewer 7 EIC,Editor,Reviewer
Don't get duplicate value with ID 7
How to combine DisplayName Details? How to write the Query?
8条答案
按热度按时间vkc1a9a21#
In SQL-Server you can do it in the following:
QUERY
TEST DATA
OUTPUT
zpgglvta2#
Output -
My post about string aggregation:
http://www.codeproject.com/Articles/691102/String-Aggregation-in-the-World-of-SQL-Server
luaexgnf3#
For MySQL:
SELECT id, GROUP_CONCAT(displayname) FROM tableName GROUP BY id
Refer: http://www.sqlines.com/mysql/functions/group_concat
xmq68pz94#
SQL Server 2017+ and SQL Azure: STRING_AGG
Starting with the next version of SQL Server, we can finally concatenate across rows without having to resort to any variable or XML witchery.
STRING_AGG (Transact-SQL)
bn31dyow5#
and in case of oracle database
a0x5cqrl6#
to change the separator use
this will change separator from comma to semicolon :)
vjhs03f77#
Thank you all,
4ioopgfo8#
In Oracle SQL, you can use
LISTAGG
.