![](/img/trans.png)
[英]MySQL - How to create a new table that is a join on primary key of two existing tables
[英]Can I join two tables in MYSQL and create a new table
我想在可能的情況下加入這兩個表后創建一個新表
SELECT * FROM tablepeople
JOIN tableinfo
ON tablepeople.id = tableinfo.ctrlid
是的,您可以使用CREATE TABLE AS ... SELECT FROM
構造,如下所示; 考慮到new_table
尚不存在的事實
create table new_table as
SELECT * from tablepeople
join tableinfo
on tablepeople.id = tableinfo.ctrlid
CREATE TEMPORARY TABLE [table_name] ( [query] );
要么
CREATE TABLE [table_name] ( [query] );
您可以使用
創建表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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.