SQL Select Union的应用

表A:

订单号       入库单号       数量       入库数量
  001                                  500
  002                                  300
  003                                  400

表B:

订单号       入库单号       入库数量
  001                R01                250
  001                R02                250
  002                R03                100
  002                R04                200
  003                R05                150
  003                R06                250

现在生成表如下:

订单号       入库单号       数量       入库数量
  001                                  500
  001                R01                               250
  001                R02                               250
  002                                  300
  002                R03                                
  002                R04                               200
  003                                  400
  003                R05                               150
  003                R06                               250

SQL语句如下:

select a.订单号,a.入库单号,a.数量,a.入库数量 from a
union
select b.订单号,b.入库单号,null,b.入库数量 from b
posted @ 2005-10-16 00:40  泡面 @ 幸福  阅读(1779)  评论(3编辑  收藏  举报