Seleciona as linhas definidas por qualquer consulta e as introduz em uma nova tabela. Você pode especificar se deseja criar uma tabela temporário ou persistente.
Sintaxe
[ WITH with_subquery [, ...] ] SELECT [ TOP number ] [ ALL | DISTINCT ] * | expression [ AS output_name ] [, ...] [ EXCLUDE column_list ] INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table [ FROM table_reference [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | { EXCEPT | MINUS } } [ ALL ] query ] [ ORDER BY expression [ ASC | DESC ] [ LIMIT { number | ALL } ] [ OFFSET start ]
Para obter detalhes sobre os parâmetros deste comando, consulte SELECT.
Exemplos
Selecione todas as linhas da tabela EVENT e crie uma tabela NEWEVENT:
select * into newevent from event;
Selecione o resultado de uma consulta agregada em uma tabela temporária chamada PROFITS:
select username, lastname, sum(pricepaid-commission) as profit
into temp table profits
from sales, users
where sales.sellerid=users.userid
group by 1, 2
order by 3 desc;