mablevj mablevj - 10 days ago 6
Android Question

Select data from different tables as shown in below , sqlite Android

I want to select

db_amount
and
cr_amount
from tables
debit
and
credit
respectively with ordered by
date


cr_amount db_amount created
--------------------------------------------------
1000 NULL 2011-07-01 00:10:16
2000 NULL 2011-07-08 10:11:45
6000 NULL 2011-07-22 00:10:16
NULL 3000 2011-07-09 04:12:18


For example, if I have a table credit:

id cr_amount created
--------------------------------------------------
1 1000 2011-07-01 00:10:16
2 2000 2011-07-08 10:11:45
3 6000 2011-07-09 04:12:18


And a table debit:

id db_amount created
--------------------------------------------------
1 3000 2011-07-09 04:12:18


I have tried with
UNION ALL
but the result was as shown below

cr_amount created
-----------------------------------
1000 2011-07-01 00:10:16
2000 2011-07-08 10:11:45
6000 2011-07-09 04:12:18
3000 2011-07-09 04:12:18


any help will be really appreciated.
thanks.

Answer

You may need to put both columns in the 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
Comments