mysql同一个表中两条数据进行合并

mysql同一个表中两条数据进行合并

<!--获取公司和主营产品信息-->
  <select id="selectUserExt" resultMap="getUserExt">
    select u.user_id,u.user_name,u.company_name,u.are_name,u.address,u.web,u.tel,u.fax,u.u_describe,
        GROUP_CONCAT(m.mainproduct_name) AS mainproduct_name
    FROM `user` u
    INNER JOIN mainproduct m
    on user_id=m.company_id
    AND user_id=#{userId,jdbcType=INTEGER}
  </select>

  <!--获取联系人信息-->
  <select id="selectPeopleExt" resultMap="getUserExt">
    select CONCAT(c.principal_name,' ', b.business_department_name,' ',c.mphone) as principal_name
    FROM contactinfo c,business_department b
    WHERE c.business_department_id=b.business_department_id
    AND company_id=#{userId,jdbcType=INTEGER}
    UNION
    select CONCAT(c.principal_name, ' ',b.business_department_name,' ',c.mphone) as principal_name
    FROM contactinfo c,business_department b
    WHERE c.business_department_id=b.business_department_id
    AND company_id=#{userId,jdbcType=INTEGER}
</select>

图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!