Drei
Drei

Reputation: 13

Can I join two tables in MYSQL and create a new table

I want to make a new table after joining this two tables if it is possible

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

Upvotes: 1

Views: 18948

Answers (4)

santhosh Sagar
santhosh Sagar

Reputation: 1

This query will join two table and create the new table with that two joined table

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

Upvotes: 0

Rahul
Rahul

Reputation: 77896

Yes, you can use CREATE TABLE AS ... SELECT FROM construct like below; considering the fact that the new_table doesn't already exists

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

EDIT:

Based on the latest comment, use a table alias to get around this

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

Upvotes: 9

kkrkuldeep
kkrkuldeep

Reputation: 83

you can use

Create table 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;

Upvotes: 0

gamer
gamer

Reputation: 9

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

OR

CREATE TABLE [table_name] ( [query] );

Upvotes: -1

Related Questions