Skip to main content

CREATE TABLE AS

Create a new table from the result of a query.

Syntax

Parameters

ParameterDescription
table_nameName of the table to create
select_statementA SELECT query whose result set defines the columns and rows of the new table

Examples

Create from a SELECT

CREATE TABLE top_articles AS
SELECT id, title, views
FROM articles
ORDER BY views DESC
LIMIT 100;

Create from a filtered query

CREATE TABLE engineering_articles AS
SELECT id, title, body, published_at
FROM articles
WHERE category = 'engineering' AND views > 1000;

See also