从两个表中读取数据

时间:2016-09-26 11:14:51

标签: android sqlite union-all

考虑下面列出的表格

Table credit

id    cr_amount  created_date
1     1000       2011-07-01
2     2000       2011-07-08
3     6000       2011-07-09

以下是Table debit条目。

id   dr_amount  created_date
1    3000       2011-07-09

需要阅读cr_amount排序的上表中的dr_amountcreated_datecreated date列,如下所示。

cr_amount  dr_amount   created_date
1000        NULL         2011-07-01
2000        NULL         2011-07-08
6000        NULL         2011-07-22
NULL        3000         2011-07-09

1 个答案:

答案 0 :(得分:2)

您可能需要将两列都放在union all中:

select cr_amount,Null as 'db_amount',created from table_credit
union all
select Null,db_amount,created from table_debit
order by created