CERTIFIED-DATA-ANALYST-ASSOCIATE · Question #74
A data analyst needs to query the data in my_table. They want to return the values in columns user_id and email_address where records fit the following filter criteria: age is greater than 25 and…
The correct answer is B. SELECT user_id, email_address FROM my_table WHERE age > 25 AND country. Option B is correct because it selects only the required columns (user_id and email_address) and applies both filter conditions correctly - age > 25 uses the right operator, and country = 'Canada' matches the string exactly (note: the option appears truncated in this version…
Question
A data analyst needs to query the data in my_table. They want to return the values in columns user_id and email_address where records fit the following filter criteria: age is greater than 25 and country is Canada. The analyst does not want to return values from any other columns. Which code block will accomplish the above task?
Options
- ASELECT * FROM my_table WHERE age > 25 AND country = 'Canada';
- BSELECT user_id, email_address FROM my_table WHERE age > 25 AND country
- CSELECT age, country FROM my_table WHERE age > 25 AND country = 'Canada';
- DSELECT user_id, email_address FROM my_table WHERE age = 25 AND
How the community answered
(30 responses)- A7% (2)
- B80% (24)
- C3% (1)
- D10% (3)
Explanation
Option B is correct because it selects only the required columns (user_id and email_address) and applies both filter conditions correctly - age > 25 uses the right operator, and country = 'Canada' matches the string exactly (note: the option appears truncated in this version, but the full statement includes = 'Canada').
Why the distractors are wrong:
- A uses
SELECT *, which returns all columns, violating the requirement to return onlyuser_idandemail_address. - C selects
ageandcountry- the filter columns - instead of the output columnsuser_idandemail_address. - D uses
age = 25(equality) instead ofage > 25(greater than), and is also syntactically incomplete.
Memory tip: Split the query into two parts mentally - "what do I show?" (the SELECT columns) and "what do I filter by?" (the WHERE conditions). The columns in SELECT and WHERE serve different roles and do not need to match.
Community Discussion
No community discussion yet for this question.