AWS Certified Data Engineer – Associate (DEA-C01) — Question 96
A company has a data warehouse that contains a table that is named Sales. The company stores the table in Amazon Redshift. The table includes a column that is named city_name. The company wants to query the table to find all rows that have a city_name that starts with "San" or "El".
Which SQL query will meet this requirement?
Answer options
- A. Select * from Sales where city_name ~ ‘$(San|El)*’;
- B. Select * from Sales where city_name ~ ‘^(San|El)*’;
- C. Select * from Sales where city_name ~’$(San&El)*’;
- D. Select * from Sales where city_name ~ ‘^(San&El)*’;
Correct answer: B
Explanation
The correct answer is B because the regular expression '^' indicates that the match should occur at the beginning of the string, which is needed to find city names that start with 'San' or 'El'. Option A incorrectly uses '$(...)', which does not anchor the match to the beginning. Options C and D use '&' instead of '|', which is incorrect syntax for specifying alternatives in regex.