Create Table As (CTAS)

The CREATE TABLE AS statement creates a new table and populates it with the queried data.

CREATE TABLE new_table_name AS query;

CREATE TABLE yeni_filmler AS SELECT film_id, title, release_year,
length, rating FROM film INNER JOIN film_category USING (film_id)
WHERE category_id = 1;
SELECT * FROM yeni_filmler ORDER BY title;

The above query is executed to display the columns.

CREATE TABLE IF NOT EXISTS film_reytingleri (rating, film_count)
AS SELECT rating, COUNT (film_id) FROM film GROUP BY rating;

As a result of the query, a table with 2 columns (rating, film_count) named film_reytingleri was created. Table data is taken from the film table.