Reputation: 71
I have two tables named as wsbill and wspay. wsbill used to store billing details and wspay used to store payment details. i want to viw transaction details of these two tables.
Structure of my table is,
mysql> select * from wspay;
+------------+-------+------+
| WDATE | NAME | AMT |
+------------+-------+------+
| 2015-01-28 | Bilal | 2000 |
| 2015-01-30 | Bilal | 5000 |
+------------+-------+------+
mysql> select * from wsbill;
+------------+---------+-------+------+--------+-------+
| WDATE | WSELLER | BILL | LESS | REASON | FAMT |
+------------+---------+-------+------+--------+-------+
| 2015-01-27 | Bilal | 11000 | 1000 | test | 10000 |
| 2015-01-29 | Bilal | 12000 | 1000 | test | 11000 |
+------------+---------+-------+------+--------+-------+
Now i want output like,
2015-01-27 Bilal 11000 1000 test 10000
2015-01-28 Bilal 2000
2015-01-29 Bilal 12000 1000 test 11000
2015-01-30 Bilal 5000
which means order by date. How can i do this?
Upvotes: 0
Views: 33
Reputation: 776
SELECT * from ( select * from table1
union
select * from table2 )order by WDATE DESC
Upvotes: 0
Reputation: 3875
Try this:
select *
from (
select wdate, name, amt, null as less, null as reason, null as famt
from wspay
union
select wdate, wseller, bill, less, reason, famt
from wsbill
) x
order by wdate
Upvotes: 2