我可以在MYSQL中连接两个表并创建一个新表吗

c9qzyr3d  于 2023-06-28  发布在  Mysql
关注(0)|答案(4)|浏览(177)

如果可能的话,我想把这两个表连接起来后再做一个新表

  1. SELECT * FROM tablepeople
  2. JOIN tableinfo
  3. ON tablepeople.id = tableinfo.ctrlid
44u64gxh

44u64gxh1#

是的,你可以像下面这样使用CREATE TABLE AS ... SELECT FROM结构;考虑到new_table并不存在

  1. create table new_table as
  2. SELECT * from tablepeople
  3. join tableinfo
  4. on tablepeople.id = tableinfo.ctrlid

编辑:

根据最新的评论,使用表别名来解决这个问题

  1. CREATE TABLE mytable3 AS
  2. SELECT t1.*
  3. FROM mytable1 t1
  4. JOIN mytable2 t2 ON t1.ID=t2.ID
mepcadol

mepcadol2#

您可以使用
新建表new_table

  1. Create table new_table as
  2. SELECT * FROM customers
  3. LEFT JOIN orders ON customers.idcustomers = orders.idorders
  4. UNION
  5. SELECT * FROM customers
  6. RIGHT JOIN orders ON customers.idcustomers = orders.idorders;
juzqafwq

juzqafwq3#

此查询将连接两个表并使用这两个连接的表创建新表

  1. Syntex: select * into new_table_name
  2. From table1 as t1
  3. Join table2 as t2 ON t2.column name =
  4. t1.column name;
  5. Example: select * into emp_detls
  6. From employee as emp
  7. Join employeeDOB AS edob ON edob.employeeID
  8. = emp.e_id
8yparm6h

8yparm6h4#

  1. CREATE TEMPORARY TABLE [table_name] ( [query] );

  1. CREATE TABLE [table_name] ( [query] );

相关问题