Reputation:
I have two table, and I want to mix them forever (something like join
, but not temporarily, forever in the database).
My tables:
// table1
+------+----------+-----------+
| id | name | color |
+------+----------+-----------+
| 1 | peter | |
| 2 | jack | |
| 3 | ali | |
+------+----------+-----------+
// table2
+------+----------+
| id | color |
+------+----------+
| 1 | pink |
| 2 | blue |
| 3 | red |
+------+----------+
Now, I want to create a new table which is composed of two tables. something like this:
// main_table
+------+----------+-----------+
| id | name | color |
+------+----------+-----------+
| 1 | peter | pink |
| 2 | jack | blue |
| 3 | ali | red |
+------+----------+-----------+
I can do it with join
:
select t1.id, t1.name, t2.color from table1 t1 inner join table2 t2 on t1.id=t2.id
So, Is it possible to I do it with a sql query in phpmyadmin and create a new table of it ?
Upvotes: 2
Views: 121
Reputation: 1269973
You can use create table as
:
create table newtable as
select t1.id, t1.name, t2.color
from table1 t1 inner join
table2 t2
on t1.id = t2.id;
However, a view might be sufficient:
create view v_table as
select t1.id, t1.name, t2.color
from table1 t1 inner join
table2 t2
on t1.id = t2.id;
Upvotes: 1