Joining two columns

Hi, I have two tables, one containing DoB and one containing Age. I'd like to be able to create a thrird table with both DoB and Age side by side. Test contains Age

MariaDB [mysql]> select * from test;
+------+
| Age  |
+------+
|    8 |
|    8 |
|    9 |
|    8 |
|    9 |
|    8 |
|    9 |
|    8 |
|    8 |
|    8 |
|    8 |
|    8 |
|    9 |
|    9 |
|    9 |
|    8 |
|    8 |
|    8 |
|    9 |
|    9 |
|    8 |
|    9 |
|    9 |
|    8 |
|    8 |
|    8 |
|    9 |
|    8 |
|    9 |
|    9 |
|    8 |
+------+
31 rows in set (0.000 sec)

test1 contains DoB

MariaDB [mysql]> select * from test1;
+------------+
| DoB        |
+------------+
| 2010-11-15 ||    8 |

| 2010-07-12 |
| 2010-03-12 |
| 2010-09-23 |
| 2010-02-12 |
| 2010-07-01 |
| 2010-03-07 |
| 2010-12-27 |
| 2010-08-25 |
| 2010-08-11 |
| 2010-09-25 |
| 2010-08-21 |
| 2010-03-24 |
| 2010-04-08 |
| 2010-05-21 |
| 2010-12-07 |
| 2010-12-22 |
| 2010-09-15 |
| 2010-04-06 |
| 2010-05-14 |
| 2010-11-21 |
| 2010-05-27 |
| 2010-04-20 |
| 2010-12-14 |
| 2010-12-28 |
| 2010-07-09 |
| 2010-03-14 |
| 2010-07-30 |
| 2010-01-28 |
| 2010-04-20 |
| 2010-08-03 |
+------------+
31 rows in set (0.000 sec)

I'd like to get a table with the output as such:

| 2010-11-15 ||     8|
| 2010-07-12 ||     8|
| 2010-03-12 ||     9|
| 2010-09-23 ||     8|
| 2010-02-12 ||     9|
| 2010-07-01 ||     8|
| 2010-03-07 ||     9|
| 2010-12-27 ||     8|
| 2010-08-25 ||     8|
| 2010-08-11 ||     8|
| 2010-09-25 ||     8|
| 2010-08-21 ||     8|
| 2010-03-24 ||     9|
| 2010-04-08 ||     9|
| 2010-05-21 ||     9|
| 2010-12-07 ||     8|
| 2010-12-22 ||     8|
| 2010-09-15 ||     8|
| 2010-04-06 ||     9|
| 2010-05-14 ||     9|
| 2010-11-21 ||     8|
| 2010-05-27 ||     9|
| 2010-04-20 ||     9|
| 2010-12-14 ||     8|
| 2010-12-28 ||     8|
| 2010-07-09 ||     8|
| 2010-03-14 ||     9|
| 2010-07-30 ||     8|
| 2010-01-28 ||     9|
| 2010-04-20 ||     9|
| 2010-08-03 ||     8|

Answer Answered by Ian Gilfillan in this comment.

Given what you've provided, there is no way to combine the two tables, as both tables contain a single field with nothing linking them. Take a look at the concept of foreign keys. Secondly, ''age'' is not a good choice for a database field, as its constantly changing, and can be generated from the date of birth at all times, for example with something like:

SELECT TIMESTAMPDIFF(YEAR, DoB, CURDATE()) AS age FROM test1;

For inserting data from one or more tables into another table, see INSERT SELECT.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.