I'm building a MySQL query for a search function, now I want to order the outcome in a certain way using an array of ID's.
I've been able to do this by using a piece of MySQL similar to this:
SELECT id, name
FROM mytable
WHERE id IN (77, 3, 123, 1)
ORDER BY FIELD(id, 77, 3, 123, 1)
But I'm wondering if it's possible to Order by FIELD
or by FIND_IN_SET
without setting the IN()
within the Select query.
I don't want to use the IN() statement because I also expect results that aren't in the array of ID's
Hopefully someone can push me in the right direction,