Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:48:26+00:00 2026-05-26T09:48:26+00:00

I want the result set of a database query to have a certain order.

  • 0

I want the result set of a database query to have a certain order. The information I want to order by is not contained in the database, but dynamically generated in code (so I cannot use ORDER BY).

Is there a way to sort a dataset after executing the database query? (I don’t need indexed access but only want to iterate over all records.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:48:27+00:00Added an answer on May 26, 2026 at 9:48 am

    There is a possibility that shares similarities with Jens’ answer (+1) but gets to the result in a slightly different fashion.

    Given an existing table:

    create table somedata (id integer, name char(20));
    insert into somedata values ( 1, 'Tim' );
    insert into somedata values ( 2, 'Bob' );
    insert into somedata values ( 3, 'Joe' );
    

    If you know the desired short order (either by processing the table or some query result from it), create a temp table that has some key value to match the desired rows from the original table and then the sort order data:

    create table #sortorder( id integer, sortvalue integer );
    

    Set the sortvalue field in the temp table to contain the desired order (it could be any sortable data type – doesn’t have to be integer):

    insert into #sortorder values ( 1, 15 );
    insert into #sortorder values ( 2, 12 );
    insert into #sortorder values ( 3, 5 );
    

    Then generate the results with a join against the table that provides the sort order:

    select sd.* from somedata sd, #sortorder so 
             where sd.id = so.id
             order by so.sortvalue; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big database result set and I want get specific rows from
Normally when I want to query large result set using Mysql I write this
I have a MYSQL stored procedure SP1() that returns a result set. I want
I have a very complex Linq to SQL query that returns a result set
I have a result set I pull from a large database: $result = mysql_query($sql);
I want to display result set of Years between From date - To date
I got a result set in array format and i want to make square
I have two results from a data set. I want to add both results
I have a problem with using QueryDSL to create a query. I want to
I have a LINQ result set I'm trying to filter in a strange and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.