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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:23:16+00:00 2026-06-09T09:23:16+00:00

This might not make any sense, but what i’m trying to do is select

  • 0

This might not make any sense, but what i’m trying to do is select a column based on when another column is least. For example, I have 3 int columns and 3 varchar columns

In the below example Unit = int, and Link = varchar

Unit1|Link1|Unit2|Link2|Unit3|Link3
72|www.google.com|43|www.yahoo.com|9212|www.lycos.com

In the above example Unit2 is least so I’d want to select Link2.

This is how i’m selecting least, so any help would be awesome

select Least(
                       Coalesce(myTable.Unit1,
                                myTable.Unit2,
                                myTable.Unit3),
                       Coalesce(myTable.Unit1,
                                myTable.Unit2,
                                myTable.Unit3),
                       Coalesce(myTable.Unit1,
                                myTable.Unit2,
                                myTable.Unit3))
                       AS LowestUnit
from myTable
  • 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-09T09:23:18+00:00Added an answer on June 9, 2026 at 9:23 am

    One approach:

    SELECT CASE WHEN Unit1 = LEAST(Unit1,Unit2,Unit3) THEN Link1 
                WHEN Unit2 = LEAST(Unit1,Unit2,Unit3) THEN Link2
                WHEN Unit3 = LEAST(Unit1,Unit2,Unit3) THEN Link3
           END AS LinkL
    

    (You could use an ELSE Link3 in place of that third WHEN for an equivalent result, I just went with checking all three, and letting the ELSE default to NULL.)

    Equivalent and more terse:

    SELECT CASE LEAST(Unit1,Unit2,Unit3)
                WHEN Unit1 THEN Link1 
                WHEN Unit2 THEN Link2
                WHEN Unit3 THEN Link3
           END AS LinkL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize that this question might not make sense to some, but I was
I created this Annotation class This example might not make sense because It'll always
This might not have a major usecase in projects, but I was just trying
Reading the documentation it seems this might not be possible, but it seems that
This question might not seem very technical but, out of curiosity,I want to know
I know this might sounds not reasonable, and might be a bad design. But
This might be an easy one, but I'm not really experienced with sql. I
This might be a stupid question, but I was wondering whether or not you
I'm not sure if this might be a rather stupid question. But is it
I know this might seem a controversial question but it really is not meant

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.