如何创建一个由两个 table 组成的 table

how to create one table which is composed of two tables

我有两个 table,我想永远混合它们 (类似于 join,但不是暂时的,永远在数据库中)

我的tables:

// table1 
+------+----------+-----------+
|  id  |   name   |   color   |
+------+----------+-----------+
|  1   |   peter  |           |
|  2   |   jack   |           |
|  3   |   ali    |           |
+------+----------+-----------+

// table2
+------+----------+
|  id  |   color  |
+------+----------+
|  1   |   pink   |
|  2   |   blue   |
|  3   |   red    |
+------+----------+

现在,我想创建一个由两个 table 组成的新 table。像这样:

// main_table 
+------+----------+-----------+
|  id  |   name   |   color   |
+------+----------+-----------+
|  1   |   peter  |   pink    |
|  2   |   jack   |   blue    |
|  3   |   ali    |   red     |
+------+----------+-----------+

我可以用 join:

select t1.id, t1.name, t2.color from table1 t1 inner join table2 t2 on t1.id=t2.id

那么,我可以在 phpmyadmin 中使用 sql 查询并创建一个新的 table 吗?

您可以使用 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;

但是,一个视图可能就足够了:

create view v_table as
    select t1.id, t1.name, t2.color
    from table1 t1 inner join
         table2 t2
         on t1.id = t2.id;