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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:16:10+00:00 2026-06-11T13:16:10+00:00

I have to compare three COLUMNS for each row and get the MAX data

  • 0

I have to compare three COLUMNS for each row and get the MAX data from these columns. My sample data is:

create table sept18 ( t1 number, t2 number, t3 number );

insert all
  into sept18 values (1,2,3)
  into sept18 values (-1,-2,3)
  into sept18 values (1,null,13)
  into sept18 values (-1,-2,-3)
  into sept18 values (-1,0,0)
select * from dual;

My operation should show the three columns and a field with the maximum value from each row. For instance, for the first and second rows it is 3, for the third it is 13, -1 for the fourth and 0 for the fifth.

How can I achieve this? Do I have to use partition?

  • 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-11T13:16:11+00:00Added an answer on June 11, 2026 at 1:16 pm

    No, you don’t have to use an analytic query (I assume that’s what you mean by partition?). An analytic function is used to compute an aggregate amount, of some description. You’re not looking to aggregate anything across a column; you want to find the maximum in a row.

    For this you need to use the greatest() function, the opposite of least().

    select a.*, greatest(t1, t2, t3)
      from sept18 a
    

    Be warned; both of these functions will return null if a single column is null. How you deal with this is your decision. My normal tactic is to use nvl() with a completely ridiculous value. This can be dangerous, as the “ridiculous” value you choose might become correct so ensure you understand your data.

    select a.*, greatest(nvl(t1,-9999), nvl(t2, -9999), nvl(t3, -9999))
      from sept18 a
    

    Here’s a little SQL Fiddle to demonstrate both queries.

    If all columns are null then you can descend even further into ridiculousness. Either you have to nullif() the greatest(), or, more simply, just use WHERE to exclude rows where all columns are null.

    One little extra point. The existence of a table sept18 seems a little suspicious. If you actually have one table per day then you should consider normalising your database and creating, for instance, a temporal table, which has a created_date column.

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

Sidebar

Related Questions

My problem is this; I have to order a table of data. Each row
I have three tables (these are the relevant columns): Table1 bookingid, person, role Table2
I'm trying to get data from file. The file first has three lines of
I have the following table for storing user data: e.g. TABLE: users COLUMNS: ...
I have two rows from a table that has many columns. How do I
Suppose you have thousands of rows of data coming from a table Index |
I have a table (client) with 20+ columns that is mostly historical data. Something
I have a MySQL table (A) which has, amongst others, three columns named day,
I have a table with four columns. Three of which are settings for the
I have to compare three dates in linq query (datetime a < datetime b

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.