1

I am getting some records from sorted table and would like to ask some other table for records with the same ... lets say ... id.

SELECT * FROM duckies WHERE fluffy_id IN (<array_of_fluffy_ids>) ...

Is there any way to order the query result exactly the same way as fluffy_ids in IN() clause?

0

1 Answer 1

7

Yes, there is. Use FIELD() function:

SELECT 
  * 
FROM 
  duckies 
WHERE 
  fluffy_id IN (<array_of_fluffy_ids>) 
ORDER BY 
  FIELD(fluffy_id, <array_of_fluffy_ids>)
Sign up to request clarification or add additional context in comments.

1 Comment

Great, thank you! I will accept the answer in 10 minutes. It does exactly what I wanted.

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.