Azure Table Storage Query Examples
This document provides a collection of practical examples for querying data in Azure Table Storage using the OData protocol.
Basic Queries
Retrieve All Entities
To retrieve all entities from a table, simply make a GET request to the table resource.
GET /MyTable() HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Retrieve Specific Entities by PartitionKey and RowKey
To retrieve a single entity, specify both the PartitionKey and RowKey in the query.
GET /MyTable(PartitionKey='abc',RowKey='123') HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Filtering Data
Filter by PartitionKey
Use the $filter query option to filter entities based on their PartitionKey.
GET /MyTable?$filter=PartitionKey eq 'MyPartition' HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Filter by Multiple Properties (AND)
Combine conditions using the logical and operator.
GET /MyTable?$filter=PartitionKey eq 'Customers' and Age gt 30 HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Filter by String Properties
Use functions like startswith, endswith, and substringof for string comparisons.
GET /MyTable?$filter=startswith(Name, 'A') eq true HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
GET /MyTable?$filter=substringof('gmail.com', Email) eq true HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Filter by Date/Time Properties
Date and time values are represented in ISO 8601 format.
GET /MyTable?$filter=Timestamp ge datetime'2023-01-01T00:00:00Z' HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Selecting Properties
Select Specific Properties
Use the $select query option to retrieve only the specified properties.
GET /MyTable?$select=PartitionKey,RowKey,Name,Email HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Ordering Results
Order Results
Use the $orderby query option to sort results. Specify asc for ascending and desc for descending order.
GET /MyTable?$orderby=Name asc HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
GET /MyTable?$orderby=Age desc,Name asc HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Paging
Limit Number of Results (Top)
Use the $top query option to limit the number of entities returned.
GET /MyTable?$top=10 HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Continue Querying (Continuation Token)
When a query returns more results than can fit in a single response, Azure Table Storage includes a odata.nextLink property in the response. Use this link in subsequent requests to retrieve the next page of results.
Example response snippet:
{
"value": [ ... entities ... ],
"odata.nextLink": "/MyTable?$filter=...&$skiptoken=..."
}
To get the next page, make a GET request to the URL provided in odata.nextLink.
Advanced Queries
Query by RowKey Range
You can query for a range of RowKey values within a specific PartitionKey.
GET /MyTable?$filter=PartitionKey eq 'MyPartition' and RowKey ge '100' and RowKey lt '200' HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Querying with Functions (e.g., length)
Example using the length function on a string property.
GET /MyTable?$filter=length(Description) gt 50 HTTP/1.1
Host: .table.core.windows.net
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0;NetFx
x-ms-version: 2019-02-02
Note on OData Version
The examples above use DataServiceVersion: 3.0;NetFx. Ensure your client library or request headers are configured appropriately for the OData version supported by Azure Table Storage.