I'm fairly new to JavaScript and don't know how to perform the following action. I have a table named info in the database which is similar to below
id | city | description |
---|---|---|
10 | Paris | some desc |
2 | New York | some desc |
4 | Munich | some desc |
7 | Paris;2 | some desc |
17 | Munich;2 | some desc |
I want to get the highest id based on the city so I have written this filter which gets called using await models.city.findAll(options)
;
if (filtered) {
options.where = {
id: {
$in: models.sequelize.literal('SELECT MAX(id) from info GROUP BY city'),
},
};
}
Now as you can see the following works only if the city field was not overloaded by in my case some other processes modifies that and concatenates a number with ;
used as a delimiter.
What I want to do is for this filter to work by grouping by city and splitting using the delimiter to avoid getting duplicates.
I'm not sure how to do this using sequelize as I'm fairly new to this.