Retrieving Unique Objects¶
Unique objects can be retrieved from a column of the requested table by using the distinct
property in the invocation. The distinct
parameter is a boolean value which defaults to false
.
Consider the following table schema for a data table called Employees
:
This table contains the column firstName
, and by passing the true
value to the distinct
property when calling this method, only unique values will be returned in the response:
Important
Make sure to replace xxxx in the domain name in the sample requests below to the one assigned to your application.
GET https://xxxx.backendless.app/api/data/Employees?props=firstName&distinct=true
The query returns the following result which contains only unique names:
[
{
"___class": "Employees",
"firstName": "Anna"
},
{
"___class": "Employees",
"firstName": "Simon"
},
{
"___class": "Employees",
"firstName": "Andrew"
}
]
Aggregate Functions¶
The distinct
parameter can be also used with such aggregate functions as:
Average¶
Suppose you need to calculate an average value for a set of objects, but you want to skip identical records. The following example will retrieve only unique values from the age
column and calculate the average age of all employees.
Important
Make sure to replace xxxx in the domain name in the sample requests below to the one assigned to your application.
GET https://xxxx.backendless.app/api/data/Employees?props=Avg(distinct age)
Count¶
The example below will count only unique values in the firstName
column and return an integer value in the response:
GET https://xxxx.backendless.app/api/data/Employees?props=Count(distinct firstName)
Sum¶
The example below will calculate the sum of unique values in the bonusPayment
column and return an integer value in the response:
GET https://xxxx.backendless.app/api/data/Employees?props=Count(distinct bonusPayment)