Azure Digital Twins query language reference: FROM clause

This document contains reference information on the FROM clause for the Azure Digital Twins query language.

The FROM clause is the second part of a query. It specifies the collection and any joins that the query will act on.

This clause is required for all queries.

SELECT ... FROM DIGITALTWINS

Use FROM DIGITALTWINS (not case sensitive) to refer to the entire collection of digital twins in an instance.

You can optionally add a name to the collection of digital twins by adding the name to the end of the statement.

Syntax

Basic:

--SELECT ...
FROM DIGITALTWINS

To name the collection:

--SELECT ...
FROM DIGITALTWINS <collection-name>

Examples

Here's a basic query. The following query returns all digital twins in the instance.

SELECT *
FROM DIGITALTWINS

Here's a query with a named collection. The following query assigns a name T to the collection, and still returns all digital twins in the instance.

SELECT *
FROM DIGITALTWINS T

SELECT ... FROM RELATIONSHIPS

Use FROM RELATIONSHIPS (not case sensitive) to refer to the entire collection of relationships in an instance.

You can optionally add a name to the collection of relationships by adding the name to the end of the statement.

Note

This feature cannot be combined with JOIN.

Syntax

Basic:

--SELECT ...
FROM RELATIONSHIPS

To name the collection:

--SELECT ...
FROM RELATIONSHIPS <collection-name>

Examples

Here's a query that returns all relationships in the instance.

SELECT *
FROM RELATIONSHIPS

Here's a query that returns all relationships coming from twins A, B, C, or D.

SELECT *
FROM RELATIONSHIPS
WHERE $sourceId IN  ['A', 'B', 'C', 'D']

Using FROM and JOIN together

The FROM clause can be combined with the JOIN clause to express cross-entity traversals in the Azure Digital Twins graph.

For more information on the JOIN clause and crafting graph traversal queries, see Azure Digital Twins query language reference: JOIN clause.

Limitations

The following limits apply to queries using FROM.

For more information, see the following sections.

No subqueries

No subqueries are supported within the FROM statement.

Example (negative)

The following query shows an example of what can't be done as per this limitation.

SELECT * 
FROM (SELECT * FROM DIGITALTWINS T WHERE ...)

Choose FROM RELATIONSHIPS or JOIN

The FROM RELATIONSHIPS feature cannot be combined with JOIN. You'll have to select which of these options works best for the information you'd like to select.