Problem in getting results in order

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepk84
    New Member
    • Oct 2006
    • 97

    Problem in getting results in order

    Hi all,

    I have an sql to retrieve some data. the format of the query is like,

    select field1,field2 from tablename where field1 in(1,2,3);

    This is fine and it returns the details correctly.
    It gives result in the ascending order of what i give in the "in"

    ie. even if I give like

    select field1,field2 from tablename where field1 in(3,1,2);

    then also it's returning the results based on 1,2,3 order.
    I want the order not to be in ascending or descending but in the
    same order as i give in where condition.
    please help...

    Thanks and Regards,
    sand...
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    You need to use ORDER BY clause for the desired results.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Use the ORDER BY FIELD like this:

      [php]
      SELECT field1,field2 FROM tablename WHERE field1 in(3,1,2)
      ORDER BY FIELD(field1, '3', '2', '1')[/php]
      Ronald

      Comment

      Working...