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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:56:30+00:00 2026-05-12T19:56:30+00:00

If I have 3 columns, X, Y, Z, that are each a number, how

  • 0

If I have 3 columns, X, Y, Z, that are each a number, how can I get each row returned greatest to least, and then the rows return greatest to least?

So if I had:

X    Y    Z
8    7    9
1    2    3
4    6    5

how could I get:

9    8    7
6    5    4
3    2    1
  • 1 1 Answer
  • 1 View
  • 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-12T19:56:30+00:00Added an answer on May 12, 2026 at 7:56 pm
    SELECT CASE WHEN X >= Y && X >= Z THEN X
                WHEN Y >= Z && Y >= X THEN Y
                ELSE Z END,
    CASE WHEN X >= Y && X < Z THEN X
         WHEN X >= Z && X < Y THEN X
         WHEN Y >= X && Y < Z THEN Y
         WHEN Y >= Z && Y < Z THEN Y
         ELSE Z END,
    CASE WHEN X <= Y && X <= Z THEN X
         WHEN Y <= Z && Y <= X THEN Y
         ELSE Z
    FROM Table
    ORDER BY CASE WHEN X >= Y && X >= Z THEN X
                WHEN Y >= Z && Y >= X THEN Y
                ELSE Z END;
    

    Off of the top of my head, that should work. I’m not going to make promises on performance. If this were Microsoft SQL, I’d be tempted to make a second table which stored the values per row in order, and have a Trigger set up to keep the second table up to date.

    Now, that’s pretty obviously only going to work if you have 3 columns. 4 columns is more of a headache, and that’s really where you need to start thinking up a new way to store the info, such as a table like this:

    ------------------------------
    | row_id | column_id | value |
    ------------------------------
    |   1    |   'X'     |   7   |
    |   1    |   'Y'     |   8   |
    |   1    |   'Z'     |   9   |
    |   2    |   'X'     |   3   |
    

    … and so forth.

    Once you’ve got the data in this format, doing some sort of:

    SELECT row_id, value FROM TABLE ORDER BY row_id, value DESC;
    

    suddenly becomes super-easy.

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

Sidebar

Related Questions

I have 46 rows of information, 2 columns each row (Code Number, Description). These
I have a table containing a large number of rows. Each row has 2
I have a table containing a large number of rows. Each row has 2
Here is the problem: I have two columns in a table that, for each
I have a table that has three different date columns, so I set each
I have a CSV file that has rows, where data for some columns only
I have a table with a number of columns that will be used to
I would like to get the average for certain columns for each row. I
In this jsfiddle http://jsfiddle.net/littlesandra88/eGRRb/ have I submit buttons that are auto-generated. Each table row
I know that using the following codes will make each column have unique values,

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.