Note
UPDATE 9/22: read the General Availability announcement. Some of the top asks we have received on Azure Active Directory were for better sorting, counting, and filtering capabilities. We are excited to announce that we are now providing these capabilities on Azure Active Directory objects to developers through Microsoft Graph! In addition to addressing these important. Hello IT Pros, I have collected the Microsoft Defender for Endpoint (Microsoft Defender ATP) advanced hunting queries from my demo, Microsoft Demo and Github for your convenient reference. As we knew, you or your InfoSec Team may need to run a few queries in your daily security monitoring task.
Effective November 2020:
- Common Data Service has been renamed to Microsoft Dataverse. Learn more
- Some terminology in Microsoft Dataverse has been updated. For example, entity is now table and field is now column. Learn more
This article will be updated soon to reflect the latest terminology.
If you want to retrieve data for an entity set, use a GET
request. When retrieving data, you can apply query options to set criteria for the data you want and the entity properties that should be returned.
Basic query example
This example queries the accounts entity set and uses the $select
and $top
system query options to return the name property for the first three accounts:
Request
Response
Limits on number of entities returned
Unless you specify a smaller page size, a maximum of 5000 entities will be returned for each request. If there are more entities that match the query filter criteria, a @odata.nextLink
property will be returned with the results. Use the value of the @odata.nextLink
property with a new GET
request to return the next page of data.
Note
Queries on model entities aren’t limited or paged. More information:Query Metadata using the Web API

Use $top
query option
You can limit the number of results returned by using the $top
system query option. The following example will return just the first three account entities.
Note
Limiting results using $top
will prevent odata.maxpagesize
preference from being applied. You can use odata.maxpagesize
preference or $top
, but not both at the same time. For more information about odata.maxpagesize
, see Specify the number of entities to return in a page.
You should also not use $top
with $count
.
Specify the number of entities to return in a page
Use the odata.maxpagesize
preference value to request the number of entities returned in the response.
Focus dashcam organizer for sale. Note
You can’t use an odata.maxpagesize
preference value greater than 5000.
The following example queries the accounts entity set and returns the name
property for the first three accounts.
Request
Response
Use the value of the @odata.nextLink
property to request the next set of records. Don’t change or append any additional system query options to the value. For every subsequent request for additional pages, you should use the same odata.maxpagesize preference value used in the original request. Also, cache the results returned or the value of the @odata.nextLink
property so that previously retrieved pages can be returned to.
Note
The value of the @odata.nextLink
property is URI encoded. If you URI encode the value before you send it, the XML cookie information in the URL will cause an error.
Apply system query options
Each of the system query options you append to the URL for the entity set is added using the syntax for query strings. The first is appended after [?] and subsequent query options are separated using [&]. All query options are case-sensitive as shown in the following example.
Request specific properties
Use the $select
system query option to limit the properties returned as shown in the following example.
Important Insyde software driver.
This is a performance best practice. If properties aren’t specified using $select
, all properties will be returned.
When you request certain types of properties you can expect additional read-only properties to be returned automatically.
If you request a money value, the _transactioncurrencyid_value
lookup property will be returned. This property contains only the GUID value of the transaction currency so you could use this value to retrieve information about the currency using the transactioncurrency EntityType. Alternatively, by requesting annotations you can also get additional data in the same request. More information: Retrieve data about lookup properties
If you request a property that is part of a composite attribute for an address, you will get the composite property as well. For example, if your query requests the address1_line1
property for a contact, the address1_composite
property will be returned as well.
Filter results

Use the $filter
system query option to set criteria for which entities will be returned.
Standard filter operators
The Web API supports the standard OData filter operators listed in the following table.

Operator | Description | Example |
---|---|---|
Comparison Operators | ||
eq | Equal | $filter=revenue eq 100000 |
ne | Not Equal | $filter=revenue ne 100000 |
gt | Greater than | $filter=revenue gt 100000 |
ge | Greater than or equal | $filter=revenue ge 100000 |
lt | Less than | $filter=revenue lt 100000 |
le | Less than or equal | $filter=revenue le 100000 |
Logical Operators | ||
and | Logical and | $filter=revenue lt 100000 and revenue gt 2000 |
or | Logical or | $filter=contains(name,'(sample)') or contains(name,'test') |
not | Logical negation | $filter=not contains(name,'sample') |
Grouping Operators | ||
( ) | Precedence grouping | (contains(name,'sample') or contains(name,'test')) and revenue gt 5000 |
Note
This is a sub-set of the 11.2.5.1.1 Built-in Filter Operations. Arithmetic operators and the comparison has operator are not supported in the Web API.
All filter conditions for string values are case insensitive.
Standard query functions
The Web API supports these standard OData string query functions:
Function | Example |
---|---|
contains | $filter=contains(name,'(sample)') |
endswith | $filter=endswith(name,'Inc.') |
startswith | $filter=startswith(name,'a') |
Note
This is a sub-set of the 11.2.5.1.2 Built-in Query Functions. Date
, Math
, Type
, Geo
and other string functions aren’t supported in the web API.
Microsoft Dataverse Web API query functions
Dataverse provides a number of special functions that accept parameters, return Boolean values, and can be used as filter criteria in a query. See Web API Query Function Reference for a list of these functions. The following is an example of the Between Function searching for accounts with a number of employees between 5 and 2000.
More information: Compose a query with functions.
Use Lambda operators
The Web API allows you to use two lambda operators, which are any
and all
to evaluate a Boolean expression on a collection.
any
operator
The any
operator returns true
if the Boolean expression applied is true
for any member of the collection, otherwise it returns false
. The any
operator without an argument returns true
if the collection is not empty.
Example
The example given below shows how you can retrieve all Account entity records that have atleast one email with 'sometext' in the subject.
all
operator
The all
operator returns true
if the Boolean expression applied is true
for all members of the collection, otherwise it returns false
.
Example
The example given below shows how you can retrieve all Account entity records that have all associated tasks closed.
The example given below shows how you can retrieve all Account entity records that have atleast one email with 'sometext' in the subject and whose statecode is active.
The example given below shows how you can also create a nested query using any
and all
operators.
Filter parent records based on values of child records
The example given below shows how you can use the /any operator to retrieve all the account records which have:
- any of their linked opportunity records' budget greater than or equal to 300, and
- the opportunity records' have no description, or
- the opportunity records' description contains the term 'bad'.
Request
Filter records based on single-valued navigation property
Navigation properties let you access data related to the current entity. Single-valued navigation properties correspond to Lookup attributes that support many-to-one relationships and allow setting a reference to another entity. More information: Navigation properties.
You can filter your entity set records based on single-valued navigation property values. For example, you can retrieve child accounts for the specified account.
For example:
- Retrieve all the matching accounts for a specified Contact ID

Request
Response
- Retrieve child accounts for the specified Account ID
Request
Response
Filter results based on values of collection-valued navigation properties
Note
It is possible to use $filter
within $expand
to filter results for related records in a Retrieve operation. You can use a semi-colon separated list of system query options enclosed in parentheses after the name of the collection-valued navigation property. The query options that are supported within $expand
are $select
, $filter
, $top
and $orderby
. More information: Options to apply to expanded entities.
The two options for filtering results based on values of collection-valued navigation properties are:
- Construct a query using Lambda operators
Lambda operators allow you to apply filter on values of collection properties for a link-entity. The below example retrieves the records of systemuser
entity type that are linked with team
and teammembership
entity types, that means it retrieves systemuser
records who are also administrators of a team whose name is 'CITTEST'.
More information: Use Lambda operators.
- Iterate over results filtering individual entities based on values in the collection using multiple operations
To get the same results as the example above, you can retrieve records of two entity types and then iteratively match the values in the collection of one entity to the value in the other entity, thereby filtering entities based on the values in the collection.
Follow the steps in the below example to understand how we can filter results using the iteration method:
- Get a distinct list of team._administratorid_value values.
GET [OrganizationURI]/api/data/v9.1/teams?$select=_administratorid_value&$filter=_administrator_value ne null
- Then loop through the returned values to remove duplicates and get a distinct list. i.e. Create a new array, loop through the query results, for each check to see if they are already in the new array, if not, add them. This should give you a list of distinct
systemuserid
values - The way you would do this in JavaScript vs C# would be different, but essentially you should be able to get the same results.
- Query systemuser using ContainValues Query Function to compare the
systemuserid
values with the list collected in Step 1.
Order results
Specify the order in which items are returned using the $orderby
system query option. Use the asc
or desc
suffix to specify ascending or descending order respectively. The default is ascending if the suffix isn’t applied. The following example shows retrieving the name and revenue properties of accounts ordered by ascending revenue and by descending name.
Aggregate and Grouping results
By using $apply
you can aggregate and group your data dynamically. Possible use cases with $apply
:
Use Case | Example |
---|---|
List of unique statuses in the query | accounts?$apply=groupby((statuscode)) |
Aggregate sum of the estimated value | opportunities?$apply=aggregate(estimatedvalue with sum as total) |
Average size of the deal based on estimated value and status | opportunities?$apply=groupby((statuscode),aggregate(estimatedvalue with average as averagevalue) |
Sum of estimated value based on status | opportunities?$apply=groupby((statuscode),aggregate(estimatedvalue with sum as total)) |
Total opportunity revenue by Account name | opportunities?$apply=groupby((parentaccountid/name),aggregate(estimatedvalue with sum as total)) |
Primary contact names for accounts in 'WA' | accounts?$apply=filter(address1_stateorprovince eq 'WA')/groupby((primarycontactid/fullname)) |
Last created record date and time | accounts?$apply=aggregate(createdon with max as lastCreate) |
First created record date and time | accounts?$apply=aggregate(createdon with min as firstCreate) |
The aggregate functions are limited to a collection of 50,000 records. Further information around using aggregate functionality with Dataverse can be found here: Use FetchXML to construct a query.
Additional details on OData data aggregation can be found here: OData Extension for Data Aggregation Version 4.0. Note that Dataverse supports only a sub-set of these aggregate methods.
Use parameter aliases with system query options
You can use parameter aliases for $filter
and $orderby
system query options. Parameter aliases allow for the same value to be used multiple times in a request. If the alias isn’t assigned a value it is assumed to be null.
Without parameter aliases:
With parameter aliases:
You can also use parameter aliases when using functions. More information: Use Web API functions
Retrieve a count of entities
Use the $count
system query option with a value of true
to include a count of entities that match the filter criteria up to 5000.
Note
The count value does not represent the total number of entities in the system. It is limited by the maximum number of entities that can be returned. More information: Limits on number of entities returned
If you want to retrieve the total number of records for an entity beyond 5000, use the RetrieveTotalRecordCount Function.
The response @odata.count
property will contain the number of entities that match the filter criteria irrespective of an odata.maxpagesize
preference limitation.
The following example shows that there are ten accounts that match the criteria where the name contains “sample”, but only the first three accounts are returned.
Request
Response
If you don’t want to return any data except for the count, you can apply $count
to any collection to get just the value.
Request
Response
Include formatted values
When you want to receive formatted values for properties with the results, use the odata.include-annotations
preference with the value of OData.Community.Display.V1.FormattedValue
. The response will include these values with properties that match the following naming convention:
The following example queries the accounts entity set and returns the first record, including properties that support formatted values.
Request
Response
Retrieve related entities with query
Use the $expand
system query option in the navigation properties to control what data from related entities is returned. More information: Retrieve related entities with query.
Retrieve data about lookup properties
If your query includes lookup properties you can request annotations that will provide additional information about the data in these properties. Most of the time, the same data is can be derived with knowledge of the single-valued navigation properties and the data included in the related entities. However, in cases where the property represents a lookup attribute that can refer to more than one type of entity, this information can tell you what type of entity is referenced by the lookup property. More information: Lookup properties
There are two additional types of annotations available for these properties,
Annotation | Description |
---|---|
Microsoft.Dynamics.CRM.associatednavigationproperty | The name of the single-valued navigation property that includes the reference to the entity. |
Microsoft.Dynamics.CRM.lookuplogicalname | The logical name of the entity referenced by the lookup. |
These properties also can include formatted values as described in Include formatted values. Just like formatted values, you can return the other annotations using the odata.include-annotations
preference set to the specific type of annotation you want, or you can set the value to '*'
and return all three. The following sample shows the request and response to retrieve information about the incident entity _customerid_value
lookup property with annotations included.
Request
Response
Retrieve related entities by expanding navigation properties
Retrieve related entities by expanding collection-valued navigation properties
If you expand on collection-valued navigation parameters to retrieve related entities for entity sets, an @odata.nextLink
property will be returned for the related entities. You should use the value of the @odata.nextLink
property with a new GET
request to return the required data.
The following example retrieves the tasks assigned to the top 5 account records.
Request
Response
Retrieve related entities by expanding both single-valued and collection-valued navigation properties
The following example demonstrates how you can expand related entities for entity sets using both single- and collection-valued navigation properties. As explained earlier, expanding on collection-valued navigation properties to retrieve related entities for entity sets returns an @odata.nextLink
property for the related entities. You should use the value of the @odata.nextLink
property with a new GET
request to return the required data.
In this example, we are retrieving the contact and tasks assigned to the top 3 accounts.
Request
Response
Use change tracking to synchronize data with external systems
The change tracking feature allows you to keep the data synchronized in an efficient manner by detecting what data has changed since the data was initially extracted or last synchronized. Changes made in entities can be tracked using Web API requests by adding odata.track-changes
as a preference header. Preference header odata.track-changes
requests that a delta link be returned which can subsequently be used to retrieve entity changes.
More information: Use change tracking to synchronize data with external systems.
Column comparison using the Web API
The following example shows how to compare columns using the Web API:
More information: Use column comparison in queries
Microsoft Query Language
See also
Search across entity data using relevance search
Work with Quick Find’s search item limit
Web API Query Data Sample (C#)
Web API Query Data Sample (Client-side JavaScript)
Perform operations using the Web API
Compose Http requests and handle errors
Create an entity using the Web API
Retrieve an entity using the Web API
Update and delete entities using the Web API
Associate and disassociate entities using the Web API
Use Web API functions
Use Web API actions
Execute batch operations using the Web API
Impersonate another user using the Web API
Perform conditional operations using the Web API
Note
Can you tell us about your documentation language preferences? Take a short survey.
The survey will take about seven minutes. No personal data is collected (privacy statement).
- MS Access Tutorial
- MS Access Useful Resources
- Selected Reading
A query is a request for data results, and for action on data. You can use a query to answer a simple question, to perform calculations, to combine data from different tables, or even to add, change, or delete table data.
As tables grow in size they can have hundreds of thousands of records, which makes it impossible for the user to pick out specific records from that table.
With a query you can apply a filter to the table's data, so that you only get the information that you want.
Queries that you use to retrieve data from a table or to make calculations are called select queries.
Queries that add, change, or delete data are called action queries.
You can also use a query to supply data for a form or report.
In a well-designed database, the data that you want to present by using a form or report is often located in several different tables.
The tricky part of queries is that you must understand how to construct one before you can actually use them.
Create Select Query
If you want to review data from only certain fields in a table, or review data from multiple tables simultaneously or maybe just see the databased on certain criteria, you can use the Select query. Let us now look into a simple example in which we will create a simple query which will retrieve information from tblEmployees table. Open the database and click on the Create tab.
Click Query Design.
Microsoft Query 97
In the Tables tab, on the Show Table dialog, double-click the tblEmployees table and then Close the dialog box.
In the tblEmployees table, double-click all those fields which you want to see as result of the query. Add these fields to the query design grid as shown in the following screenshot.
Now click Run on the Design tab, then click Run.
The query runs, and displays only data in those field which is specified in the query.
