group_concat(A,' ',B,' ',C) as Name,
then using this php for displaying
<td><?php echo $row['Name']; ?></td>
using this query returns Name X,Y
but i prefer to have the names not comma separated rather line break X then Y new line
Any idea?
The difference here is while CONCAT is used to combine values across columns, GROUP_CONCAT gives you the capability to combine values across rows. It's also important to note that both GROUP_CONCAT and CONCAT can be combined to return desired results.
GROUP_CONCAT is a function which concatenates/merges the data from multiple rows into one field. It is a GROUP BY function which returns a string if the group contains at least 1 non-null value, if it does not, it returns a Null value.
Show activity on this post. I'm using GROUP_CONCAT() in a MySQL query to convert multiple rows into a single string. However, the maximum length of the result of this function is 1024 characters.
The GROUP_CONCAT() function in MySQL is used to concatenate data from multiple rows into one field. This is an aggregate (GROUP BY) function which returns a String value, if the group contains at least one non-NULL value. Otherwise, it returns NULL.
For MySQL (or plain text) output You could use \n
as a separator:
SELECT GROUP_CONCAT(column1 SEPARATOR '\n') FROM table1;
I use this very often when I need to get many new-line-separated values in one row for other processing.
I figured it out. this is the correct way to add line break as seperator in the browser:
group_concat(A,' ',B,' ',C separator '<br>') as Name,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With