• /
  • EnglishEspañolFrançais日本語한국어Português
  • Se connecterDémarrer

Query data with Lens

preview

We're still working on this feature, but we'd love for you to try it out!

This feature is currently provided as part of a preview program pursuant to our pre-release policies.

You can write Lens queries in Query Builder, Notebooks, and custom dashboards. This page explains how to query data in each platform.

Conseil

When querying data sources, Lens doesn't restrict the number of rows you can retrieve from external sources. However, queries to NRDB through Lens maintain the same 5,000 row limit as NRQL.

Prerequisites

Before you start:

  • Verify you have the necessary permissions to query data sources.
  • If you need to query external data sources, ensure the connectors are set up.

Query in the query builder

  1. Go to one.newrelic.com.
  2. From the drawer at the bottom of the page, open the Query your data console.
  3. In the query editor, select Lens data (SQL) as the query language.
  4. If you want to query NRDB data, select the account from the account selector. Other data connectors are available at the organization level and don't require account selection.
  5. Write your SQL query using the table reference format: connection_name.schema.table
  6. Click Run. The chart renders based on your query results.

Save query in Notebooks

Notebooks are shareable documents that combine queries, visualizations, and markdown documentation.

  1. Go to one.newrelic.com.
  2. From the drawer at the bottom of the page, open the Query your data console.
  3. Enable the toggle beside Notebooks. At the bottom of the page, the + SQL button appears.
  4. Click + SQL to add a SQL block.
  5. If you want to query NRDB data, select the account from the account selector. Other data connectors are available at the organization level and don't require account selection.
  6. Write your SQL query using the table reference format: connection_name.schema.table
  7. Click Run. The chart renders based on your query results.
  8. Click Save.

For further guidance, refer to the Notebooks documentation.

Query in custom dashboards

You can add SQL-based charts to your custom dashboards:

  1. Go to one.newrelic.com > Dashboards.
  2. Create a new dashboard or open an existing one.
  3. Click + Add widget and select a chart type.
  4. In the query editor, select Lens data (SQL) as the query language.
  5. If you want to query NRDB data, select the account from the account selector. Other data connectors are available at the organization level and don't require account selection.
  6. Write your SQL query using the table reference format: connection_name.schema.table
  7. Click Run. The chart renders based on your query results.
  8. Click Add to dashboard. For further guidance, refer to the custom dashboards documentation.

    Important

    SQL-based charts are only supported in private dashboards. Public dashboards don't support SQL queries.

SQL syntax

Lens uses ANSI SQL to query data sources, so you don't need to learn database-specific query languages.

Table reference format

When writing queries in Lens, reference tables using the format:

connection_name.schema.table

For example:

  • telemetry.Transaction - Query the Transaction table from the telemetry (NRDB) connector
  • snowflake.sales.orders - Query the orders table from a Snowflake connector named "snowflake" in the "sales" schema
  • gsheets.default.employees - Query a Google Sheets connector named "gsheets"

Supported SQL statements

Lens supports standard ANSI SQL statements including:

  • SELECT - Query data from one or more tables
  • JOIN - Combine data from multiple tables (including cross-database joins)
  • WHERE - Filter results
  • GROUP BY - Aggregate data
  • ORDER BY - Sort results
  • LIMIT - Restrict the number of returned rows
  • WITH (CTEs) - Define common table expressions for complex queries

Performance tips

  • Use filters early: Apply WHERE clauses to reduce the amount of data processed.
  • Limit results: Use LIMIT to restrict returned rows when exploring data.
  • Consider materialized views: For frequently-run complex queries, create a materialized view.
  • Optimize joins: When joining large tables, filter data before the join when possible.

Query syntax differences from NRQL and examples

Lens uses ANSI SQL instead of NRQL. The following examples show key differences and common query patterns.

Materialized views

Store query results for better performance.

Lens overview

Learn about Lens features, use cases, and permissions.

Set up connectors

Connect to external data sources.

Droits d'auteur © 2026 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.