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

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

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

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

44u64gxh1#

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

create table new_table as
SELECT * from tablepeople 
join tableinfo 
on tablepeople.id = tableinfo.ctrlid

编辑:

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

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

mepcadol2#

您可以使用
新建表new_table

Create table new_table as
SELECT * FROM customers
LEFT JOIN orders ON customers.idcustomers = orders.idorders
UNION
SELECT * FROM customers
RIGHT JOIN orders ON customers.idcustomers = orders.idorders;
juzqafwq

juzqafwq3#

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

Syntex: select * into new_table_name
From table1 as t1
Join table2 as t2 ON t2.column name = 
t1.column name;


Example: select * into emp_detls
From employee as emp
Join employeeDOB AS edob ON edob.employeeID 
= emp.e_id
8yparm6h

8yparm6h4#

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

CREATE TABLE [table_name] ( [query] );

相关问题