sql - MySql: get data from two tables with grouping by Date -
sql - MySql: get data from two tables with grouping by Date -
i have 2 table same columns, want merge them , grouped date
table1: order_payments_detail
| payment_by | amount( debit in result) | added_on | | ali | 1000 | 2014-09-21 | | aslam | 2000 | 2014-09-25 | | akram | 4000 | 2014-09-28 |
table2: orders
| cust_name | amount( credit in result)| added_on | | shop1 | 1000 | 2014-09-22 | | shop2 | 2000 | 2014-09-26 | | shop3 | 4000 | 2014-09-29 |
result this
| particulars| debit | credit | added_on | | ali | 1000 | null | 2014-09-21 | | shop1 | null | 1000 | 2014-09-22 | | aslam | 2000 | null | 2014-09-25 | | shop2 | null | 2000 | 2014-09-26 | | akram | 4000 | null | 2014-09-28 | | shop3 | null | 4000 | 2014-09-29 |
you can readily union all
:
select payment_by, amount debit, null credit, added_on order_payments_detail union select cust_name, null, amount, added_on orders order added_on;
by "grouped date", assume mean "ordered date".
mysql sql
Comments
Post a Comment