我的数据库中有10个表用于日志数据。我想从一些条件中获取所有这些数据,例如order by。这些表中有一个公共列ORDERID。
例如: -
表1 - :ORDER_AREA_1
RECID ORDERID ORDER TO
1 A1_001 JIM
2 A1_002 SAM
3 A1_003 TIM
表2 - :ORDER_AREA_2
RECID ORDERID ORDER TO
1 A2_001 ALBERT
2 A2_002 JOHN
3 A2_003 KEVEN
表3 - :ORDER_AREA_3
RECID ORDERID ORDER TO
1 A3_001 SPENCER
2 A3_002 CRISTY
3 A3_003 JOE
现在我希望结果为
ORDERID ORDER TO
A1_001 JIM
A1_002 SAM
A1_003 TIM
A2_001 ALBERT
A2_002 JOHN
A2_003 KEVEN
A3_001 SPENCER
A3_002 CRISTY
A3_003 JOE
我想要一个会以这种方式产生的查询 请帮助解决这个问题。
答案 0 :(得分:2)
select ORDERID,`ORDER TO` from ORDER_AREA_1
union all
select ORDERID,`ORDER TO` from ORDER_AREA_2
union all
select ORDERID,`ORDER TO` from ORDER_AREA_3