How can I order a query result same as the id specified in the WHERE condition?

You can do this using FIELD() : SELECT ... ORDER BY FIELD(`test`. `id`, 562, 553, 572).

You can do this using FIELD(): SELECT ... ORDER BY FIELD(`test`. `id`, 562, 553, 572).

ORDER BY CASE test. Id WHEN 562 THEN 0 WHEN 553 THEN 1 WHEN 572 THEN 2 END.

One way is like this: SELECT * FROM test JOIN test2 ON test. Id=test2. Id WHERE test.Id IN (562,553,572) ORDER BY CASE test.

Id WHEN 562 THEN 1 WHEN 553 THEN 2 WHEN 572 THEN 3 ELSE 4 END; You don't need GROUP BY unless you are computing aggregates. The ELSE clause is superfluous here, but it is generally a good idea to include it.

– Nirmal Oct 21 '10 at 6:38 @Nirmal: yes - I don't know which DBMS support the FIELD function (but it certainly isn't all of them); OTOH, I don't know of a DBMS that does not support CASE. – Jonathan Leffler Oct 21 '10 at 13:31.

Could do something with FIND_IN_SET(): SELECT * FROM test JOIN test2 ON test. Id = test2. Id WHERE test.Id IN (562,553,572) ORDER BY FIND_IN_SET(test.

Id, '562,553,572').

Thank you sir :-) – learner Oct 21 '10 at 7:50.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions