Site Fuse! programming, design, hosting, promotion and advertising tips for webmasters

Create new table using two existing tables

Home  \  Forums  \  Databases  \  Create new table using two existing tables

2Guns

Call me dumb but I found this while I was trying to find a way to create a new table by combining two tables that exists in my database...

Basically what you gotta do is to join two tables just like you join them with select command...

CREATE TABLE new_table_name
SELECT *
FROM table1 t1, table2 t2, WHERE t1.id = t2.id;

you can also specify which columns you want in your new table;

CREATE TABLE new_table_name
SELECT t1.title, t1.address, t2.name, t2.age
FROM table1 t1, table2 t2, WHERE t1.id = t2.id;