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 6131395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:58:10+00:00 2026-05-23T16:58:10+00:00

Table temp ID Status 1 completed 2 approved 3 paid 4 cancel 5 approved

  • 0

Table temp

ID  Status
1   completed
2   approved
3   paid
4   cancel
5   approved
6   paid

I want to display above recored as per bellow table without using union.because this is client requirement, so please provide help for this.

Table temp

ID  Status
1   completed
2   approved
5   approved
3   paid
6   paid
4   cancel
  • 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-23T16:58:10+00:00Added an answer on May 23, 2026 at 4:58 pm

    Almost identical to Dan’s answer, but for SQL Server (Or any standards SQL database system):

    SELECT 
      ID, 
      Status 
    FROM 
      temp 
    ORDER BY 
      CASE Status
          WHEN 'completed' THEN 1
          WHEN 'approved' THEN 2
          WHEN 'paid' THEN 3
          WHEN 'cancel' THEN 4
      END
    

    Other concerns –

    1) The title of this question appears to be misleading, since it’s not about GROUP BY at all, and,

    2) I think you have a misconception about UNION also – there’s no guarantee of the order in which results will return from a UNION or UNION ALL – In the UNION case, there’s likely to be a sort operation to help the server to eliminate duplicates, but which sort is performed is entirely up to the server and you shouldn’t rely on such a sort always being necessary. For a UNION ALL, imagine if the first query is a large query, requiring a lot of I/O, and the second query is trivial (say, all of the data required is already in memory). An obvious optimization for the server is to return the results for the second query whilst it’s still performing I/O for the first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following table: create table temp ( name int, a int, b int
The following T/SQL:- create table #temp(foo varchar(10)) insert into #temp select '' insert into
I have 1 million rows in MySql table temp and wish to multiply column
What is the difference between: CREATE TABLE #temp ( [ID] INT) INSERT INTO #temp
How can i get result My Dream Table Result CREATE TABLE #temp( [count] int
I have a temp table with the exact structure of a concrete table T
Oracle FAQ defines temp table space as follows: Temporary tablespaces are used to manage
Given a table or a temp table, I'd like to run a procedure that
I have a temp table I am creating a query off of in the
I'm creating a temp table that's the result of a stored procedure's result set.

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.