如何使用分隔符进行分组连接?

时间:2017-01-31 17:09:39

标签: mysql group-concat

 $pdo = $db->query('SELECT *, GROUP_CONCAT(friends.name, "<br>") AS result FROM animals  LEFT JOIN friends ON animals.id=friends.id');

结果:

anna
,fred

我希望得到的结果:

anna
fred

1 个答案:

答案 0 :(得分:1)

只需在SEPARATOR

中指定GROUP_CONCAT即可
$pdo = $db->query('SELECT *, GROUP_CONCAT(friends.name SEPARATOR "<br>") AS result FROM animals  LEFT JOIN friends ON animals.id=friends.id');

进一步详情及解释here