mysql - Combine two rows in select query having same id's -
i have query
select `sys_forms`.`formid`, `sys_forms`.`formname`, `sys_forms`.`formcipath`, `sys_forms_in_groups`.`ismenulink`, `sys_forms_in_groups`.`groupid` (`sys_forms`) inner bring together `sys_forms_in_groups` on `sys_forms_in_groups`.`formid` = `sys_forms`.`formid` `groupid` = 1 union select `sys_forms`.`formid`, `sys_forms`.`formname`, `sys_forms`.`formcipath`, `sys_forms_in_groups`.`ismenulink`, `sys_forms_in_groups`.`groupid` (`sys_forms`) inner bring together `sys_forms_in_groups` on `sys_forms_in_groups`.`formid` = `sys_forms`.`formid` `groupid` = 2
it returning me below data.
as can see, there 2 identical formid
.
what want if id's same rows should merged groupid
different both identical formid's.
so want them bring together in csv format result be
formid formname - - groupid ------------------------------------------------- 48 formsin groups - - 1,2
the specified result can returned query this:
class="lang-sql prettyprint-override">select f.formid , f.formname , f.formcipath , max(g.ismenulink) ismenulink , group_concat(distinct g.groupid order g.groupid) groupids `sys_forms` f bring together `sys_forms_in_groups` g on g.formid = f.formid , g.groupid in (1,2) grouping f.formid
the group_concat
aggregate combine multiple values comma separated list. (a different delimiter can specified, default comma.)
we utilize max
aggregate around ismenulink
column non-null value in place of null.
mysql sql
No comments:
Post a Comment