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

时间:2015-06-22 11:11:10

标签: mysql phpmyadmin

我有两张桌子,我希望永远将它们混合在一起(类似于join,但不是暂时的,永远在数据库中)

我的表格:

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

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

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

// 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查询并创建一个新表呢?

1 个答案:

答案 0 :(得分:1)

您可以使用<span class=""> <img height="1" width="1" alt="0001702_black-metal-bar-stool_600" class="attachment-shop_catalog wp-post-image" src="http://aalampana.com/wp-content/uploads/2015/06/0001702_black-metal-bar-stool_600.gif"> <span class="cart-loading"> <i class="fusionicon-spinner"></i> </span> </span>

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;