Bird
0
0

What will be the result of this dbt model SQL snippet?

medium📝 Predict Output Q5 of 15
dbt - Advanced Patterns

What will be the result of this dbt model SQL snippet?

SELECT id, COUNT(*) AS cnt
FROM (
  SELECT id FROM {{ ref('source_a') }}
  UNION ALL
  SELECT id FROM {{ ref('source_b') }}
) combined
GROUP BY id
AA table with unique ids and their total count from both sources combined
BA table with duplicate ids removed from both sources
CA table with ids only from source_a
DA table with ids only from source_b
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNION ALL behavior

    UNION ALL stacks all rows from both sources including duplicates.
  2. Step 2: Analyze aggregation

    Grouping by id and counting rows gives total occurrences of each id across both sources.
  3. Final Answer:

    A table with unique ids and their total count from both sources combined -> Option A
  4. Quick Check:

    UNION ALL + GROUP BY = count per id [OK]
Quick Trick: UNION ALL keeps duplicates; GROUP BY counts them [OK]
Common Mistakes:
MISTAKES
  • Confusing UNION ALL with UNION (which removes duplicates)
  • Expecting only source_a or source_b ids
  • Ignoring the COUNT aggregation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes