Courseiva

DA0-002 Data Acquisition and Preparation Practice Question

In a table with columns 'employee_id' and 'manager_id', a data analyst needs to retrieve the hierarchy level of each employee, where the top manager has manager_id NULL. Which SQL feature is best suited?

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

✓

A recursive CTE

Recursive CTE can traverse hierarchical data to compute levels.

Answer analysis

Option-by-option breakdown

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

  • ✗

    A window function with ROW_NUMBER()

    Why it's wrong here

    ROW_NUMBER() assigns an arbitrary sequential integer by sort order; it carries no parent-child linkage, so it cannot derive depth from manager_id. Recursive CTEs traverse that self-referencing relationship to compute each employee's level. ROW_NUMBER() suits ranking or de-duplication within a partition, not hierarchy traversal.

  • ✓

    A recursive CTE

    Why this is correct

    A recursive CTE references its own result set, walking manager_id links upward from each employee until the NULL root is reached, producing hierarchy levels. Self-joins need a known depth, and window functions cannot traverse variable-length parent-child chains.

  • ✗

    A GROUP BY clause with aggregation

    Why it's wrong here

    GROUP BY collapses rows into aggregates and cannot traverse parent-child links, so it cannot produce a per-employee depth value. Aggregation suits counting or summing grouped records; hierarchy traversal requires recursion, which the correct option provides through repeated self-reference.

  • ✗

    A self-join with a LEFT JOIN

    Why it's wrong here

    A single self-join matches each employee to their immediate manager only, yielding one level rather than the full depth to the NULL-rooted top. Self-joins suit fixed-depth comparisons; arbitrary-depth hierarchies need recursive querying, which repeatedly applies the join until the anchor row is reached.

About these practice questions

This DA0-002 question is part of Courseiva's 1,004-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.