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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:20:11+00:00 2026-05-28T04:20:11+00:00

I understand the normal ASC and DESC ORDER BY clause. However, I have a

  • 0

I understand the normal ASC and DESC ORDER BY clause.

However, I have a case where table contains a column unitType where unitType can be 0, 1 or 2. I need to sort my result set so that the rows returned are in a particular order depending the value of the unitType column.

This is the closest I have gotten:

SELECT * FROM `units` WHERE `unitType`=0
union 
select * from units where unitType=2
union 
select * from units where unitType=1

This lists my rows with unitType=0, followed by those with value 2 and finally 1. Is there a better way to do this? I need to alter this query to fetch rows in any particular order e.g. 2, 0, 1 etc.

  • 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-28T04:20:11+00:00Added an answer on May 28, 2026 at 4:20 am
    select * from units
    order by
      case when unitType = 0 then 1
           when unitType = 1 then 3
           else 2 end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand how LLVM JIT relates to normal no JIT compilation and the
I understand how I can change the dns settings for my domains by editing
I understand what System.WeakReference does, but what I can't seem to grasp is a
I understand that some countries have laws regarding website accessibility. In general, what are
I understand that it's considered bad design to use a normal, threaded webserver (e.g.,
To remove a normal marker from a map, I understand you simply call marker.setMap(null),
How can you tell a normal person (i.e. your mom, grand mom, your little
I don't understand the term/noun 'label image' in Matlab, and what's the normal usage
I can't understand this behaviour in my app and I'm seriously thinking burn my
Say I have a normal CSV like # helloworld.csv hello,world,,,please don't replace quoted stuff

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.