Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize select distinct rows

Is there a way to select distinct rows from a table using sequelize.js? I looked through the documentation but the "finder methods" do not specify a way to accomplish this task.

like image 318
shk Avatar asked Aug 28 '12 09:08

shk


1 Answers

You can do the following:

myModel.findAll({
  attributes: [[sequelize.fn('DISTINCT', sequelize.col('col_name')), 'alias_name']],
  where:{}
}).then(data => {}).....

taken from issues and it works.

like image 161
Ali Sherafat Avatar answered Oct 18 '22 15:10

Ali Sherafat