Mysql join three tables (2 of them similar)

Viewed 50

my customer table

id | name
==========
1  | mick
2  | george
3  | john

bakery transactions

id | customer | type    |  amount | date
============================================
1  | 3        | bread   |       1 | 2016/03/10 10:00
2  | 1        | bread   |       2 | 2016/03/10 11:00
3  | 1        | baguette|       1 | 2016/03/10 11:00
4  | 2        | bread   |       2 | 2016/03/11 09:00
5  | 3        | cookie  |       5 | 2016/03/11 09:30

greengrocery transactions

id | customer | type    |  amount | date
============================================
1  | 1        | banana  |      1  | 2016/03/10 08:00
2  | 1        | apple   |      3  | 2016/03/10 08:00
3  | 1        | orange  |      5  | 2016/03/10 14:00
4  | 3        | apple   |      8  | 2016/03/11 09:30
5  | 1        | apple   |      8  | 2016/03/12 09:30

Is it possible to get customer transactions by date from these transaction tables by the customer?

More specific, I want to get customer Id:1 transactions, ordered by date;

This is what I want.

Id| transactionType|customer | type    |  amount | date
=====================================================================
1 |  greengrocery  |       1 | banana  |      1  | 2016/03/10 08:00
2 |  greengrocery  |       1 | apple   |      3  | 2016/03/10 08:00 
2 |  bakery        |       1 | bread   |      2  | 2016/03/10 11:00
3 |  bakery        |       1 | baguette|      2  | 2016/03/10 11:00 
4 |  greengrocery  |       1 | orange  |      5  | 2016/03/10 14:00
5 |  greengrocery  |       1 | apple   |      8  | 2016/03/12 09:30
3 Answers
Related