0

With e.g.

ORDER BY field(id, 9, 1, 4)

I can order by 9,1,4.

Is it also possible to order by a comma separated string of the same table I am selecting?

I tried

ORDER BY field(id, aFieldFromTheTableIAmSelecting)

where aFieldFromTheTableIAmSelecting is "9,1,4"

But that does not work.

This question is similiar to MySQL sort order by array value

2 Answers 2

1

You can try find_in_set():

ORDER BY find_in_set(id, aFieldFromTheTableIAmSelecting)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use locate():

ORDER BY locate(concat(',', id, ','), concat(',', aFieldFromTheTableIAmSelecting, ','))

there must be no spaces inside aFieldFromTheTableIAmSelecting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.