One row means what?
Define the grain of every source and of the final target before joining anything.
The patterns I reach for repeatedly in Marketing Cloud: deterministic deduplication, ROW_NUMBER(), query grain, SARGable filtering, staging, target actions and audience segmentation.
The goal is a reference I can open during real work, not a wall of copy-paste snippets.
Use ROW_NUMBER() when the business question is “which single row should survive inside each logical group?” The hard part is not the function — it is defining the partition and ordering rules correctly.
A Golden Record rule often needs explicit source trust, status priority or permission precedence before recency. Put those rules in the window ORDER BY so the surviving row reflects the business contract.
On large Data Extensions and Data Views, where the function is applied can decide whether the database can use an index efficiently. Keep searchable columns “bare” on the left side of predicates whenever possible.
Most “my counts exploded” problems are grain problems. Define what one row represents in every source before writing the JOIN.
When one Query Activity has too many joins, scans and transformations, split the work into deterministic stages. You gain observability, smaller scans and easier failure isolation.
The SQL text is only half the Query Activity. The target action changes how the platform writes data and can become the bottleneck as the target grows.
Use NTILE() when you need balanced random buckets. Use _CustomObjectKey modulo when you need a very cheap, approximately even split on large standard Data Extensions and exact balance is not required.
A Data Extension is a relational table, not an ordered list. ORDER BY is useful when paired with TOP or window functions to select which rows win, but downstream consumers should never rely on physical row order.
These are the defaults I want to remember before promoting a query from exploration into a production automation.
Define the grain of every source and of the final target before joining anything.
PARTITION BY is not syntax decoration. It is the identity definition you are enforcing.
A readable sequence of small queries often beats one heroic query that nobody wants to debug.