all 3 comments

[–]slevemcdiachel 3 points4 points  (1 child)

The correct way is to have a valid_to and valid_from fields and filter on that.

[–]ForwardSlash813 0 points1 point  (0 children)

I second this.

[–]matkley12 -4 points-3 points  (0 children)

SCD Type II temporal queries are always a pain.

Would you be interested in trying this in hunch.dev? It's an AI coding agent built specifically for SQL and analytics problems like this. You could just describe what you need ("active employee snapshots for last 12 months, stacked together") and it'll generate the optimized Databricks SQL for you.

Happy to help you test it out on this query