New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to select row of a max record in group? #6430
Comments
Currently we only support joins on relations defined in sequelize, and we don't have great subquery support either #2787 |
OK. Thanks. It's good enough. |
Any news on this @janmeier, is this still not possible? |
I managed to get the required result as below
|
Still using a little bit of SQL, I think the following should work, using
const results = await MyModel.findAll({
attributes: [sequelize.literal('DISTINCT ON ("groupId") "MyModels"."groupId"'), 'value'],
order: [['groupId', 'DESC'], ['value', 'DESC']]
}) |
above query returning duplicate values too. is there any workaround to prevent duplicates using above query? |
a table has a groupId field, and a value field
How to select the full row record the max value in the group using sequelize?
I can only figure it out with SQL:
and let sequelize run it.
The text was updated successfully, but these errors were encountered: