I would like to join up this two tables which have had same columns name to get end results as follow. How can I do so?
Table 1, (Primary :- key date)
-------------------------------
| date | value |
-------------------------------
| 2015-05-16 03:21:46 | 2 |
-------------------------------
Table 2, (Primary :- key date)
-------------------------------
| date | value |
-------------------------------
| 2015-05-16 03:21:46 | 3 |
-------------------------------
Expecting end result
-------------------------------------------------------
| date | value(table1) | value(table2) |
-------------------------------------------------------
| 2015-05-16 03:21:46 | 2 | 3 |
-------------------------------------------------------
Just add the table names when you address the columns:
SELECT date, table1.value as value1, table2.value as value2
FROM table1
JOIN table2 USING (date)
This will give you this result:
-----------------------------------------
| date | value1 | value2 |
-----------------------------------------
| 2015-05-16 03:21:46 | 2 | 3 |
-----------------------------------------
SELECT t1.date, t1.value as value1, t2.value as value2
FROM table1 t1
JOIN table2 t2 ON t1.date = t2.date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With