How can i set the postion of a row to the first of other rows

  • Hi

    i had a requirement. I have to select a number of rows from a table. From these rows i need to set rows to the top of the others. How can i do this?.

    For ex: myTable has the following structure

    ID,KeyId,Name,City,State.

    here the field "KeyId" referes the field "ID" in the same tables itself. I want to set the row with same ID and KeyId o top of others. This means the first item in the selected result should be a row having equal ID and KeyId values. Please do a help to solve this issue.

  • U can introduce a new column and try it as below:

    select *,case when ID=KeyId then 0 else 1 end as Eq from myTable order by Eq

  • Thank you dear friend. It helped me too lot

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply