EXAMPLE :
I have two tables:
- table1 : with two columns product_id , product_name ;
- table2 : With three columns tag_name , product_id , tag_name
I would like to create a table3 from a selection of table1 and table2 with only the columns product_id , product_name , and brand_name .
CREATE TABLE tabela3 IF NOT EXISTS (
SELECT p.id_produto, p.nome_produto, m.nome_marca
FROM tabela1 p
JOIN tabela2 m
ON p.id_produto = m.id_produto
)
In this way I can get almost what I want, so that table3 is created already filled with the data of the 1 strong> 2 . What I would like to get is a table with structure based on the selection of the other tables.
I tried another way (using LIKE ):
CREATE TABLE tabela3 IF NOT EXISTS LIKE(
SELECT p.id_produto, p.nome_produto, m.nome_marca
FROM tabela1 p
JOIN tabela2 m
ON p.id_produto = m.id_produto
)
I got a nice SQL syntax error.
Is there another way to do this?