SQL Server Performance

Order of the Output Rows of a Query

Discussion in 'General Developer Questions' started by Mahesh Dara, Mar 11, 2005.

  1. Mahesh Dara New Member

    How can I get the list of rows in the same order which i specified in my WHERE Clause.
    for eg:
    SELECT *
    FROM EMP
    WHERE Id IN (89,12,54)

    Here I expect the output order should be the same which i specified in the where clause.But I am getting the sorted output.
    Can any one help me?

    Thanks
    Mahesh


    Mahesh
  2. mmarovic Active Member

    select *
    from emp
    where id in (89, 12, 54)
    order by case (id)
    when 80 then 0
    when 12 then 1
    when 54 then 2
    end

Share This Page