I hope someone could give me a general direction on this problem:
The starting point is an array of ids of db records.
array ids = [45,23,14,7];
Those records have some columns, i.e.
id,price,rating
7,$5.00,5
14,$2.00,4
23,$5.00,2
45,$5.00,5
What I would need is
- the items with max(price) (or something equivalent).
- if there is more than one item with the same price, get the ones with max(rating) (or something equivalent).
- Finally, if there is still more than one item, take the one that comes first in the array.
I’m particularly stuck with point 3. Is there a way to do that in (My)SQL, or should I do that in code?
Thank you for your reading.
In addition to the answer by @jasonlfunk you can add an extra order clause to take into account your array as well: