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

  • Home
  • SEARCH
  • 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 7576745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:59:44+00:00 2026-05-30T16:59:44+00:00

I have a table which I’m trying to arrange by 2 fields, one of

  • 0

I have a table which I’m trying to arrange by 2 fields, one of which I want to alter by case.

SELECT * FROM products WHERE disabled=’0′ ORDER BY category, status

That works fine, until status has certain values. status comes directly from xml, and we can’t really change it. We don’t know what the value is. All we know is that there are 3 certain terms which we need in certain order, then the rest ordered ascending by status.

when status='1' we want it to be 1st;
when status='D' we want it to be 2nd
when status='2' we want it to be 3rd

then the rest order by status because they carry different values..

sample output:

category | status 
electronic | 1
electronic | D
electronic | 2
electronic | 9
misc | 1
misc | 2
misc | 8
  • 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-30T16:59:45+00:00Added an answer on May 30, 2026 at 4:59 pm

    Try this:

    SELECT * 
    FROM products 
    WHERE disabled='0' 
    ORDER BY category, 
             CASE WHEN status = '1' THEN 1
             WHEN status = 'D' THEN 2
             WHEN status = '2' THEN 3
             ELSE 4 END, status
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table which display data as from Dynamic Content, I want to
I have table which contains 2 date fields. Like: id from to --- ----
I have table one which looks like this. And I want to get data
I have a table which have three fields ID,Name,aDate. I want result on distinct
I have a table which has several one to many relationships with other tables.
I have a table which needs to link one of three seperate tables, but
I have table which is filled from external application. I need to fill column
I have table view which is populated from an array grabbed from a url.
I have table which contains data along with created on date. I want to
I have table user which have fields username , password , and type .

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.