Select distinct data from tables

Hi,

is there a way to select distinct data from tables;

this are data in my table:

If I select data in this way:

const queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.addProperties('Id', 'Name');
var result = Backendless.Data.of('Customers').find(queryBuilder);

the result is:

[
    {
        "___class": "Customers",
        "Id": "1",
        "Name": "Jane"
    },
    {
        "___class": "Customers",
        "Id": "2",
        "Name": "John"
    },
    {
        "___class": "Customers",
        "Id": "1",
        "Name": "Jane"
    }
]

I want only distinct values:

[
    {
        "___class": "Customers",
        "Id": "1",
        "Name": "Jane"
    },
    {
        "___class": "Customers",
        "Id": "2",
        "Name": "John"
    }
]

I looked at the documentation, but found nothing.

Thank you,
Elena

Hi Elena,

Try adding the following line of code:

dataQuery.setGroupBy( "Name" );

The groupBy functionality applies mostly to aggregating functions, but I think it should work as you want it as well. For more information about aggregating functions, please see the doc:
https://backendless.com/docs/js/data_aggregate_functions_overview.html

Regards,
Mark

Hi @mark-piller,

it works,
thank you!

Also for retrieving distinct records without grouping you can use method .setDistinct( ) in DataQueryBuilder

great @oleg-vyalyh,
thanks