mysql
select a,
(select b from tb2 where tb2.id=tb1.id) as IDs
from tb1
tb2返回多余1行时,报错。 Subquery returns more than 1 row。
本人想,返回多行时,用逗号分隔Join起来。怎么样做到?
MS-SQL可以这样
select a,
(select b from tb2 where tb2.id=tb1.id FOR XML PATH(“”)) as IDs
from tb1
select a,
(select b from tb2 where tb2.id=tb1.id) as IDs
from tb1
tb2返回多余1行时,报错。 Subquery returns more than 1 row。
本人想,返回多行时,用逗号分隔Join起来。怎么样做到?
MS-SQL可以这样
select a,
(select b from tb2 where tb2.id=tb1.id FOR XML PATH(“”)) as IDs
from tb1
解决方案
20
MYSQL有个函数 group_concat()
20
看图: