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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:43:59+00:00 2026-06-09T19:43:59+00:00

I have columns: CAT | Val ———— none | 0 high | 5 low

  • 0

I have columns:

CAT  | Val
------------
none | 0
high | 5
low  | 100
med  | 50

as you can see, a low number is category high. (inverse logic) except for 0..

So I want to order by, so that I get the correct order for category. (none, low, med, high).

I want them in order:

CAT  | Val
------------
none | 0
low  | 100
med  | 50
high | 5

I tried this, but it unions, and then orders by. Brackets around each select causes error.

SELECT cat,  an_int FROM CATS WHERE an_int = 0
UNION
SELECT cat, an_int FROM CATS WHERE an_int <> 0 ORDER BY an_int DESC

This gives:

CAT  | Val
------------
low  | 100
med  | 50
high | 5
none | 0
  • 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-06-09T19:44:00+00:00Added an answer on June 9, 2026 at 7:44 pm

    try this:

    select * from CATS 
    order by case when cat='none' then 0 else 1 end ,Val desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two columns say Main and Sub . (they can be of same
Say I have 2 columns Product Product_Cat ------- ----------- Cat 0 Dog 0 Potatoes
I have a cat table that has the following columns: cat_id | name |
I have a CSV file with two columns: cat @ c a t dog
I have a tab delimited file of 4 columns and n number of rows.
I have a MySQL table ( tbl_filters ) with 3 columns: id , cat
I have a file with large number of columns. As a sanity check, I
I have columns Mon, Tue, wed, thu, fri, sat, sun with timestamps for every
I have a table products , and I have columns like product_name , product_id
I have one datatable. In that table I have columns named [Total Day], [Present

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.