1

I have loopback REST API, which returns all the data from MySQL table in JSON format. But, I want to query or apply filter where it returns only distinct values for a given column. For e.g in SQL we use this syntax :SELECT DISTINCT column1 FROM table_name; How can I achieve this using LoopBack Rest API? Does LoopBack support something like above? Please suggest me any other solution.

1 Answer 1

1

To my knowledge there is no filter for DISTINCT.

You can execute the sql command instead and receive the JSON object in return

var sql = "select DISTINCT name from user";
var ds = {YourModel}.app.datasources.{yourConnectionName};
ds.connector.execute(sql, [], function(err, data) {
// your code here
});

Refer http://loopback.io/doc/en/lb2/Executing-native-SQL.html for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.