DEA-C01 · Question #166
A data engineer needs to create an Amazon Athena table based on a subset of data from an existing Athena table named cities_world. The cities_world table contains cities that are located around the…
The correct answer is A. INSERT INTO cities_usa (city,state) SELECT city, state FROM cities_world WHERE. To populate a new Athena table (cities_us) with a subset of data (US cities) from an existing table (cities_world), an INSERT INTO ... SELECT FROM ... WHERE statement is used.
Question
A data engineer needs to create an Amazon Athena table based on a subset of data from an existing Athena table named cities_world. The cities_world table contains cities that are located around the world. The data engineer must create a new table named cities_us to contain only the cities from cities_world that are located in the US. Which SQL statement should the data engineer use to meet this requirement?
Options
- AINSERT INTO cities_usa (city,state) SELECT city, state FROM cities_world WHERE
- BMOVE city, state FROM cities_world TO cities_usa WHERE country='usa';
- CINSERT INTO cities_usa SELECT city, state FROM cities_world WHERE country='usa';
- DUPDATE cities_usa SET (city, state) = (SELECT city, state FROM cities_world WHERE
How the community answered
(32 responses)- A88% (28)
- B3% (1)
- C3% (1)
- D6% (2)
Why each option
To populate a new Athena table (`cities_us`) with a subset of data (US cities) from an existing table (`cities_world`), an `INSERT INTO ... SELECT FROM ... WHERE` statement is used.
The `INSERT INTO cities_usa (city,state) SELECT city, state FROM cities_world WHERE country='usa';` statement correctly selects specific `city` and `state` columns from `cities_world` where the `country` is 'usa' and inserts them into the respective columns of the `cities_usa` table. Explicitly listing the target columns makes the statement robust and clear for populating a table subset.
`MOVE` is not a standard SQL command for transferring data between tables in Amazon Athena or most SQL databases.
`INSERT INTO cities_usa SELECT city, state FROM cities_world WHERE country='usa';` would also work if the `cities_usa` table has exactly two columns named `city` and `state` in that order. However, explicitly listing the target columns in the `INSERT INTO` clause, as in option A, is generally considered better practice for clarity and robustness against minor schema changes or column order discrepancies.
`UPDATE cities_usa SET (city, state) = (SELECT city, state FROM cities_world WHERE country='usa');` is incorrect because the `UPDATE` statement is used to modify existing rows in a table, not to insert new rows or to create a table based on a selection of data from another table.
Concept tested: Athena INSERT INTO SELECT statement
Source: https://docs.aws.amazon.com/athena/latest/ug/insert-into.html
Topics
Community Discussion
No community discussion yet for this question.