422,023 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,023 IT Pros & Developers. It's quick & easy.

merge two tables make the first table come under the second having same column size

P: 2
please i am new here i need your help....
i have 2 tables: stash, exp,
and i need to merge (join) the 2 tables in a particular way;
example:
========
stash

id date amount comment
1 9/1/17 400 shoes
2 10/1/17 150 dash
3 12/1/17 100 dash

exp

id date cash comment
1 9/1/17 200 shoes
2 11/1/17 200 shoes



i want to select `date`, `amount` column from `stash` table and
also select `date`,`amount` column from `expenditure ` table
and make it one new table,and sort data to its own date
like this==>

date amount cash
-----------------------------
9/1/17 400 200
-----------------------------
10/1/17 150 -
----------------------------
11/1/17 - 200
----------------------------
12/1/17 100 -
----------------------------
Nov 22 '17 #1
Share this Question
Share on Google+
2 Replies


P: 2
how PHP MySQL Select * from 2 different tables and display the data mixed together ordered by date column in both tables
Nov 23 '17 #2

Expert 100+
P: 872
The keyword is UNION
UNION is used to combine the result from multiple SELECT statements into a single result set.
Expand|Select|Wrap|Line Numbers
  1. SELECT id, date, amount, comment FROM stash
  2. UNION
  3. SELECT id, date, cash, comment FROM exp
  4. ORDER BY date
  5.  
The 'order by' will order the result of the previous UNION,
Dec 6 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.