-
Book Overview & Buying
-
Table Of Contents
SQL for Data Analytics - Fourth Edition
By :
As discussed in Chapter 1, a relational table organizes data into rows, which are an ordered collection of columns, also known as attributes. The table also contains other properties, such as primary key/foreign key. To create a table, you can either start by filling rows in or by defining its column definitions (also called the table schema) and filling in data later.In the first approach, based on an existing dataset, you can create a table using the CREATE…AS statement. This involves running a SELECT statement to get existing data and adding a CREATE wrapper around the data.
CREATE TABLE {table_name} AS (
{select_query}
);
Here, {select_query} is any SELECT query that can be run in your database. For example, you have already executed the following SELECT statement in Chapter 1:
SELECT * FROM products LIMIT 5;
This SELECT statement will return the following result:
product_id | ...