Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Minimum value from several columns

## I have a table Table1 and I would like to do something like this. What SELECT do I need?

I have a table Table1 like this:

```ID   A  B  C
1  10 26 20
2  20 12 14
3   9 20 45```

I would like to do something like:

```select ID from Table1 where
min value from(A,B,C) < D```

So in my example for D=11, I'll get ID=1,3. What SELECT do I need?

The ideal situation would be if your database system had a function to select the lowest value from a list of parameters. MySQL, PostgreSQL and Oracle (and perhaps others) support the GREATEST and LEAST functions, so you could use LEAST like this:

```select ID
from Table1
where least(A,B,C) < 11```

If you're using some other database, you might have to hardcode the logic yourself, perhaps something like this:

```select ID
from Table1
where case when A <= B
and A <= C
then A
when B <= A
and B <= C
then B
else C end   < 11```

Ugly, eh?

Of course, if you had structured your table differently, then the query would have been a lot easier.

```ID col data
1  A   10
1  B   26
1  C   20
2  A   20
2  B   12
2  C   14
3  A    9
3  B   20
3  C   45```

Now you can use the MIN aggregate function:

```select ID
from Table1
group
by ID
having MIN(data) < 11```

Simple, yes?

## SearchDataManagement

• ### Enterprise data lakes hold the key to actionable insights

Technological pillars of sound business decisions, AI, machine learning and advanced analytics depend on the quantity, quality ...

• ### Data fabrics help data lakes seek the truth

Data fabrics can play a key role in aligning business goals with the integration, governance, reliability and democratization of ...

• ### Kyligence builds out data cloud for OLAP and big data

Kyligence is advancing the Apache Kylin project with a cloud-native offering that can help organizations more efficiently execute...

• ### Why using graph analytics for big data is on the rise

Graph analytics is being used across industries for different reasons. Read on to see how they can improve organizational ...

• ### Data governance framework key to analytics success

Successful data-driven decision-making relies on good data at its core, and it's a strong governance plan that ensures the ...

• ### Looker, Google planning plenty of analytics collaborations

While collaboration with its parent company is prominent in Looker's plans, so are investments in analytics capabilities ...

## SearchSAP

• ### More SAP leadership changes as Fox-Martin exits

SAP shuffles the executive ranks again as head of SAP customer success Adaire Fox-Martin leaves and ex-Microsoft Azure leader ...

• ### SAP Commerce Cloud dresses up digital storefronts

SAP Commerce Cloud is designed to help companies launch digital commerce sites, which may be useful for large enterprises and ...

• ### SAP Business Network, S/4HANA critical for SAP in 2021

SAP's 2021 will be a mix of familiar challenges such as moving customers off legacy systems to S/4HANA and new opportunities such...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Test your knowledge of JVM profiling tools with this quiz

Since their inclusion in Java 11, Java Flight Recorder and JDK Mission Control have become the de facto Java profiling tools for ...

• ### What's in a name? What developers can expect in Jakarta EE 9

What Oracle called the Java EE API is now called Jakarta EE API under the Eclipse Foundation. Here's what developers can expect ...

• ### Test your knowledge of variable naming conventions

What's the difference between snake case and camel case? Or kebab case and pascal case? Try this 10-question variable naming quiz...

## SearchDataCenter

• ### IBM revenues head south again as hardware, services sales dip

Reporting its sharpest decline in five years, IBM revenues for 2020 dove 5%. CEO Arvind Krishna highlights opportunities and vows...

• ### Get a template to estimate server power consumption per rack

Admins can struggle with power consumption estimation as infrastructure gets more complex. The kW-per-rack metric can help ...

• ### When the chips are down, Intel turns to VMware's Pat Gelsinger

Newly appointed Intel CEO Pat Gelsinger brings technical chops to the top of the giant chipmaker, but it may take a while to ...

## SearchContentManagement

• ### Best enterprise content management software of 2021

When it comes to ECM, there are myriad vendors to choose from. Delve into 10 tools on the market to understand their capabilities...

• ### What is the future of ECM?

ECM isn't dead; it has evolved from a technology into an approach. Learn about the history of the ECM and look forward into the ...

• ### 5 steps to a successful ECM implementation

Implementing an ECM system is a major undertaking. Check out these steps to get on the right track before you jump into the ...

## SearchHRSoftware

• ### Study finds hiring bias by recruiters, especially tired ones

Research published in "Nature" finds strong evidence of hiring bias by recruiters and uncovers notable patterns of when biased ...

• ### Diversity, equity and inclusion are hot, but tools need vetting

The diversity, equity and inclusion tools market is going mainstream, giving HR buyers more options than ever before. But due ...

• ### Biden revokes Trump's contested DEI training order

President Joe Biden has revoked an executive order from former President Donald Trump that discouraged federal agencies and ...

Close