Ad Code

Difference between GROUP_CONCAT() and CONCAT_WS()?

I have searched unsuccessfully for a satisfactory explanation on the difference between GROUP_CONCAT() and CONCAT_WS().



GROUP_CONCAT is used when you want to have non-NULL values from different column rows in a single row. For this you need to have GROUP BY to work.
CONCAT_WS is to join two or more strings.
Example
GROUP_CONCAT(CONCAT_WS(' ', firstname, lastname) ORDER BY id ASC SEPARATOR ',');
Outputs something like,
John Doe,Blah Blah,Tom Cruise,Lorem Ipsum
here space between the name is because of CONCAT_WS, while whole result in one row is because of GROUP_CONCAT



Post a Comment

0 Comments