A company has an Amazon Redshift table named Sales that includes the column city_name. The company needs to select rows where city_name begins with "San" or "El". Which SQL statement accomplishes this?
Choose an answer
Tap an option to check your answer.
Correct answer: Select * from Sales where city_name ~ '^(San|El)*';.
Why this is the answer
The correct option uses the ~ operator for regular expression matching in Redshift, which is equivalent to LIKE for simple patterns but offers more power. The ^ anchor ensures the pattern matches from the beginning of the string. The parentheses (San|El) create a group that matches either "San" or "El". The quantifier after the group is actually redundant here if the goal is to match strings starting with "San" or "El", as it would match zero or more occurrences of the entire (San|El) group. However, in Redshift, ^(San|El) would correctly match strings starting with "San" or "El". The after the group in the correct answer is technically not needed for the described requirement but doesn't invalidate the match for the initial prefixes. The incorrect options use $ which anchors to the end of the string, or & which is not a valid regular expression operator for "OR" (the pipe | is used for "OR").
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed