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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:34:53+00:00 2026-06-12T16:34:53+00:00

Assume all value columns have the same datatype. I would like the highest of

  • 0

Assume all value columns have the same datatype. I would like the highest of all values with the id in the results of a SELECT query.

Table Structure:

table_a: id, value1, value2, value3, value4, value5

Example data:

id, value1, value2, value3, value4, value5
2, 125, 256, 133, 400, 67
3, 14, 14, 14, 3, 6
4, 325, 441, 441, 975, 3

Example desired results:

id, highest_value
2, 400
3, 14
4, 975

I started down the path of a CASE statement but that got messy fast. I tired a sub-select but failed in getting that to work. Is there a clean way to compare several column values to each other?

  • 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-12T16:34:55+00:00Added an answer on June 12, 2026 at 4:34 pm

    In this case greatest function will do the work.

    with t1(id1, val1, val2, val3, val4, val5) as
    (
      select 2, 125, 256, 133, 400, 67 from dual union all
      select 3, 14,  14,  14,  3,   6  from dual union all
      select 4, 325, 441, 441, 975, 3  from dual
    )
    
    select id1 
         , greatest(val1, val2, val3, val4, val5) Res
      from t1
    

    Result:

    Id1 Res 
    ---------------
    2   400 
    3   14 
    4   975 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table T (structure below) which initially contains all-NULL values in an
I would like a query that will show a sum of columns with a
I have a table, that has many columns with all kinds of datatypes. I
Assume I have a table entries with columns: id , alias_one , alias_two ,
Assume I have following query MyModel.all().filter('transfered !=', True).fetch(limit = limit) It will works fine
assume mylist can contain the values video, audio, visual or all three. I want
Assume I have char **argv . First, how can I print out all the
In my database, assume we have a table defined as follows: CREATE TABLE [Chemical](
I have a table with around 20 columns with mostly consisting of varchars and
Let's say I have a table with 15 columns called MyTable and an UPDATE

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.