Courseiva
Data Acquisition and PreparationmediumMultiple ChoiceObjective-mapped

DA0-002 Data Acquisition and Preparation Practice Question

A data analyst wants to find customers whose last name starts with 'Mc' and have made purchases in 2023. The purchase table has a purchase_date column. Which SQL query accomplishes this?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

SELECT * FROM customers c JOIN purchases p ON c.id = p.customer_id WHERE last_name LIKE 'Mc%' AND p.purchase_date BETWEEN '2023-01-01' AND '2023-12-31';

The correct query (option D) joins the customers and purchases tables on customer ID to link customers with their purchases. It uses `LIKE 'Mc%'` to match last names starting with 'Mc' (the wildcard '%' matches any sequence of characters) and filters purchase dates within the year 2023 using `BETWEEN '2023-01-01' AND '2023-12-31'`. Options A, B, and C are incorrect: A uses `LIKE 'Mc_'` which matches exactly two characters after 'Mc', not any sequence; B uses `LIKE '%Mc%'` which matches 'Mc' anywhere in the name, not just the beginning; C uses `= 'Mc%'` which treats the wildcard as a literal character; and all three fail to join the purchases table, so they cannot filter by purchase date.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • SELECT * FROM customers WHERE last_name LIKE 'Mc_' AND YEAR(purchase_date) = 2023;

    Why it's wrong here

    'Mc_' matches exactly three characters.

  • SELECT * FROM customers WHERE last_name LIKE '%Mc%' AND purchase_date = 2023;

    Why it's wrong here

    '%Mc%' matches 'Mc' anywhere; purchase_date = 2023 is invalid.

  • SELECT * FROM customers WHERE last_name = 'Mc%' AND YEAR(purchase_date) = 2023;

    Why it's wrong here

    = does not interpret wildcards.

  • SELECT * FROM customers c JOIN purchases p ON c.id = p.customer_id WHERE last_name LIKE 'Mc%' AND p.purchase_date BETWEEN '2023-01-01' AND '2023-12-31';

    Why this is correct

    Correct use of LIKE, JOIN, and date range.

About these practice questions

One of 986 original DA0-002 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DA0-002 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DA0-002 exam.