Sequelize select distinct rows

Assuming you want to apply DISTINCT to the following query:

Tuple.findAll({attributes: ['key', 'value']});

then this is a (hackish) way to achieve what you want without having to write the whole query yourself:

Tuple.findAll({attributes: [[Sequelize.literal('DISTINCT `key`'), 'key'], 'value']});

(Tested with Sequelize v2.1.0)

Edit 2015-06-08: Still works with Sequelize v3.1.1


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.