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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:55:48+00:00 2026-06-07T01:55:48+00:00

I have a table as follow: user_id value1 value2 value3 value4 1 2 3

  • 0

I have a table as follow:

user_id value1 value2 value3 value4
1       2      3      4      null
2       null   5      2      null
3       null   null   100    3
...

Now I want to get the minimum of value1, value2, value3 and value4 and then return the user_id with the highest minimum.

I thought about using least and then group by descending, but how do I efficiently check for null?
The output for the table would be:

user_id value
3       3
1       2
2       2
  • 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-07T01:55:49+00:00Added an answer on June 7, 2026 at 1:55 am

    ~0>>1 will give you the biggest BigInt value in mysql (should be enough)

    coalesce(
          nullif(
               least(coalesce(value1, ~0>>1), coalesce(value2, ~0>>1),
                     coalesce(value3, ~0>>1), coalesce(value4, ~0>>1)), 
          ~0>>1), 
    0)
    

    or you have to do combinations (I put them all, not sure it’s necessary)

    coalesce
        (least(
           coalesce(value1, value2, value3, value4), 
           coalesce(value1, value2, value4, value3),
           coalesce(value1, value3, value2, value4),
           coalesce(value1, value3, value4, value2),
           coalesce(value1, value4, value2, value3),
           coalesce(value1, value4, value3, value2),
           coalesce(value2, value1, value3, value4),
           coalesce(value2, value1, value4, value3),
           coalesce(value2, value3, value1, value4),
           coalesce(value2, value3, value4, value1),
           coalesce(value2, value4, value1, value3),
           coalesce(value2, value4, value3, value1),
           coalesce(value3, value1, value2, value4),
           coalesce(value3, value1, value4, value2),
           coalesce(value3, value2, value1, value4),
           coalesce(value3, value2, value4, value1),
           coalesce(value3, value4, value1, value2),
           coalesce(value3, value4, value2, value1),
           coalesce(value4, value1, value2, value3),
           coalesce(value4, value1, value3, value2),
           coalesce(value4, value2, value1, value3),
           coalesce(value4, value2, value3, value1),
           coalesce(value4, value3, value1, value2),
           coalesce(value4, value3, value2, value1)
    )
    

    , 0)

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

Sidebar

Related Questions

I have a table strcuture (golf score card) as follow: HoleID int CourseID int
I'm trying to follow http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/ And have created a very simple example http://jsfiddle.net/6wbZQ/ It's
I have a table defined as follows: CREATE TABLE [dbo].[T]( [FileID] [bigint] NOT NULL,
I have the models: sales and follow. The table follow has an id, an
I have a table like the following id field_id field_value user_id 1 4 'london'
I have a table in my database used for users to follow eachother. The
I have 2 tables as follow : table1 has these fields: year,day,month,name table2 has
I have a table as follows > RowID SessionID EventID RequestedURL Date > 1
So if I have a table as follows with column date datetime employee varchar
I use JPA2 for the dao layer. Suppose i have a table as follows

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.