Skip to main content
This cookbook contains ready-to-use NQL query patterns for common data tasks. Copy these patterns and adapt them to your datasets.

Deduplication

Keep the most recent record per user

How it works: ROW_NUMBER() assigns a sequence number within each user partition, ordered by last_seen descending. QUALIFY filters to keep only the first row (most recent) for each user.

Keep the first occurrence

Deduplicate by multiple columns


Date range filtering

Last N days

Specific date range

Current month

Previous month

Rolling 12 months


Price-constrained queries

Maximum price per 1000 rows

Tiered pricing selection


Aggregations

Count by category

Daily aggregation

Monthly aggregation

Top N by category


Identity lookups

Rosetta Stone unique IDs

Filter by identifier type

Exclude specific identifier types

Access Rosetta Stone from dataset

Company-scoped Rosetta Stone

Query normalized data from a specific company only:
How it works: Using company_data._rosetta_stone limits the query to datasets owned by your company. Replace company_data with a partner’s company slug to query their shared data.

Combine normalized and original columns

Join Rosetta Stone attributes with non-normalized dataset columns:
How it works: Dataset-scoped access (company_data."123"._rosetta_stone) lets you select both normalized Rosetta Stone attributes and original dataset columns in the same query.

Data quality checks

Count nulls per column

Null percentage

Find duplicates

Value distribution


String operations

Email domain extraction

Email normalization

Phone normalization

Name standardization


Array operations

Expand array to rows

Count array elements

Access first array element

Filter by array contents


Sampling

Deterministic sample

Random sample with LIMIT


Materialized view patterns

Basic view with budget

Daily refresh with deduplication


Performance Patterns

Optimization recipes for faster queries

Complex Joins

Advanced join patterns

Functions Reference

All available functions

Filtering Guide

Complete filtering tutorial