//returns the concatenated string from multiple rows into a single string
SELECT emp_id, emp_fname, emp_lname, dept_id,
GROUP_CONCAT(designation) as "designation" FROM employee group by emp_id;
//returns the concatenated string from multiple rows into a single string
SELECT emp_id, emp_fname, emp_lname, dept_id,
GROUP_CONCAT(designation) as "designation" FROM employee group by emp_id;
GROUP_CONCAT() VS STRING_AGG()
SELECT CustName, Address, GROUP_CONCAT(Address, ' || ') As CustAddress FROM Customers Group By CustName
#Group_Concat() may not work 2018 and upgraded version
#SQL and MySQL same
SELECT CustName, Address, STRING_AGG(Address, ' || ') As CustAddress FROM Customers Group By CustName
#String_Agg() may not work some SQL version
#SQL and MySQL same
#KindHeartedRamesh
GROUP_CONCAT() VS STRING_AGG()
SELECT CustName, Address, GROUP_CONCAT(Address, ' || ') As CustAddress FROM Customers Group By CustName
#Group_Concat() may not work 2018 and upgraded version
#SQL and MySQL same
SELECT CustName, Address, STRING_AGG(Address, ' || ') As CustAddress FROM Customers Group By CustName
#String_Agg() may not work some SQL version
#SQL and MySQL same
#KindHeartedRamesh
STRING_AGG ( expression, separator ) [ <order_clause> ]
<order_clause> ::=
WITHIN GROUP ( ORDER BY <order_by_expression_list> [ ASC | DESC ] )
SELECT STRING_AGG(Genre, ',') AS Result
FROM Genres;
Result:
Result
--------------------------------------------
Rock,Jazz,Country,Pop,Blues,Hip Hop,Rap,Punk
STRING_AGG ( expression, separator ) [ <order_clause> ]
<order_clause> ::=
WITHIN GROUP ( ORDER BY <order_by_expression_list> [ ASC | DESC ] )
SELECT STRING_AGG(Genre, ',') AS Result
FROM Genres;
Result:
Result
--------------------------------------------
Rock,Jazz,Country,Pop,Blues,Hip Hop,Rap,Punk