sql 查询结果合并

144
提问者 60.186.33.19
2017-09-20 16:47 悬赏 66金币 阅读 350回答 0
操作

两张表,之前使用UNION来合并,现在表A中添加了新的字段,而表B中没有,现在
在用UNION就会报错,

请问一下这里应该用什么方法?

SELECT     `a`.`XingHaoMingChen` AS `xinghaomingchen`,     ifnull(         `c`.`LiPinBianMa`,         `a`.`XingHaoBianMa`     ) AS `xinghaobianma`,     `a`.`XiTongFenLei` AS `xitongfenlei`,     `a`.`ID` AS `lipinid`,     `b`.`NAME` AS `lipinxiaolei`,     (         CASE         WHEN (`c`.`sl` < 0) THEN             0         ELSE             `c`.`sl`         END     ) AS `lipinkucun` FROM     (         (             `chan_pin_xuan_xing_zhu_biao` `a`             LEFT JOIN `sys_common_type` `b` ON (                 (                     `a`.`XiTongFenLei` = `b`.`ID`                 )             )         )         LEFT JOIN `v_li_pin_ku_cun` `c` ON ((`a`.`ID` = `c`.`LiPinid`))     ) WHERE     (         `a`.`XiTongFenLei` IN (             SELECT                 `v_li_pin_fen_lei`.`id`             FROM                 `v_li_pin_fen_lei`         )         AND (`c`.`sl` > 0)     ) UNION     SELECT         `a`.`XingHaoMingChen` AS `xinghaomingchen`,         `a`.`XingHaoBianMa` AS `xinghaobianma`,         `a`.`XiTongFenLei` AS `xitongfenlei`,         `a`.`ID` AS `lipinid`,         `b`.`NAME` AS `lipinxiaolei`,         NULL AS `lipinkucun`     FROM         (             `chan_pin_xuan_xing_zhu_biao` `a`             LEFT JOIN `sys_common_type` `b` ON (                 (                     `a`.`XiTongFenLei` = `b`.`ID`                 )             )         )     WHERE         `a`.`XiTongFenLei` IN (             SELECT                 `v_li_pin_fen_lei`.`id`             FROM                 `v_li_pin_fen_lei`         )

程序员问题
相关问题
查看全部
收藏的人(4)