I ran a query using Amazon Athena, and I want to use the results of that query to perform further analysis using a second query. How do I do this?

Amazon Athena does not support INSERT or CTAS (Create Table As Select) queries. If you want to perform a new query against the results from a previous query, create a new table using the results of the previous query, and then run the new query against the new table. For information about retrieving the results of a previous query, see How can I access and download the results from an Amazon Athena query?

In order to create a new table using previous query results in CSV format, use a command similar to the following:

CREATE EXTERNAL TABLE IF NOT EXISTS yourTableName (col_name data_type) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION 's3://path/to/results/'

After the table is created, run your new query on the new table.

Athena, create table


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2016-12-15