Skip to main content
The SELECT statement retrieves data from one or more datasets.

Syntax

NQL requires explicit column lists. Wildcards (SELECT * and COUNT(*)) are not supported. See Explicit Column Selection for details.

Clause order

Clauses must appear in this order:
  1. SELECT — columns to return
  2. FROM — data source(s)
  3. JOIN — additional data sources with join conditions
  4. WHERE — row-level filters applied before aggregation
  5. GROUP BY — grouping for aggregations
  6. HAVING — filters applied after aggregation
  7. QUALIFY — filters based on window function results
  8. ORDER BY — result ordering
  9. LIMIT — result count restriction

Examples

Basic query:
Query with aggregation:
Query with window function and QUALIFY:

Table references

Dataset references

Reference your datasets through the company_data schema, using either the dataset’s numeric ID or its name:
Numeric IDs must be quoted because they are numeric. Dataset names don’t need quoting unless the name is a reserved keyword or contains special characters, in which case wrap it in double quotes.

Table aliases

Assign aliases to simplify column references:

Rosetta Stone table references

Rosetta Stone provides normalized access to data through three scope levels: global, company-scoped, and dataset-scoped. Each scope determines which data sources your query accesses.
To access another company’s data through Rosetta Stone, that company must have shared their data with you via an access rule. Your own company’s data (company_data) is always accessible. See Access Rules for details on data sharing.

Global access

Query all normalized data from all datasets shared with you:

Company-scoped access

Query normalized data from a specific company’s datasets:

Dataset-scoped access

Query normalized data from a specific dataset:

Choosing a scope level

See Scoping Your Queries for guidance on choosing the right scope.

Access rules

Query through pre-configured access rules using the provider’s company slug:

Column references

Fully qualified names

Use fully qualified column names to avoid ambiguity, especially in joins:

Column aliases

Assign aliases to rename columns in results:

Accessing nested fields

Access struct fields using dot notation:
Access array elements using bracket notation:
Bracket notation also works for struct fields: data['field_name']. This avoids needing to quote reserved keywords. See Reserved Keywords best practices.

Special columns

Price column

Every dataset includes _price_cpm_usd (price per 1,000 rows). Use it to filter by cost:

Rosetta Stone field access

Access normalized identity data through the ._rosetta_stone special field on any dataset:
This allows you to access both normalized Rosetta Stone attributes and non-normalized columns from the same dataset row.

Access specific identifier types

Query specific identifier types using the unique_id struct:
For complete details on scope levels and table references, see Rosetta Stone table references.

DELTA tables

The DELTA function returns only records that have changed since the last query execution. Use it for incremental data processing.

Syntax

Examples

Delta on a dataset:
Delta on Rosetta Stone:
Delta with filtering:

Subqueries

Subquery in WHERE

Subquery in FROM

EXISTS and NOT EXISTS


Common Table Expressions (WITH)

CTEs let you define named subqueries for reuse within a statement.

Syntax

Example


QUALIFY clause

The QUALIFY clause filters results based on window function values. It’s evaluated after window functions, making it useful for deduplication and ranking.

Syntax

Deduplication example

Keep only the most recent record per user:

Multiple window conditions


Budget clauses

Budget clauses control spending on data queries. They are required for CREATE MATERIALIZED VIEW statements.

BUDGET

Set a maximum total spend:

LIMIT with USD

Alternative syntax for budget limits:

Recurring limits

Set budget limits per time period:

Row limits

Limit by row count instead of cost:

SELECT DISTINCT

Remove duplicate rows from results:

CASE expressions

Conditional logic within queries:

Data Types

Primitive and complex types supported in NQL

Operators

Comparison, logical, and arithmetic operators

Functions

Built-in and Narrative-specific functions

CREATE MATERIALIZED VIEW

Complete CREATE MATERIALIZED VIEW reference