dbt - Advanced Patterns
You wrote this incremental dbt model SQL for SCD Type 2 but it duplicates current records instead of updating:
What is the main issue causing duplicates?
WITH new_data AS ( SELECT * FROM source_table WHERE updated_at > (SELECT MAX(updated_at) FROM target_table) ), updated_records AS ( SELECT * FROM target_table WHERE is_current = TRUE ) SELECT * FROM updated_records UNION ALL SELECT * FROM new_data
What is the main issue causing duplicates?
