Mircea Man Mircea Man - 14 days ago 6
SQL Question

Min/Max of two variables Hibernate SQL

How can i select the minimum of two variables in hsql query language?

I need something like

"select ... as x ... as y.... where min(x,y) <= value"


The
min()
and
max()
functions apply only to column values.

Thanks in advance.

Answer

You probably mean the LEAST value:

SELECT LEAST(x , y) FROM MYTABLE
SELECT X, Y FROM MYTABLE WHERE LEAST(X,Y) <= value 
SELECT X, Y FROM MYTABLE WHERE X <= value OR Y <= value /* this is more efficient */

You can select the minimum value among the LEAST values of the two variables in a row:

SELECT MIN(LEAST(x , y)) FROM MYTABLE