Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting numbers to a maximum value in MySQL

Is there a built-in function or some other way to limit the value of numbers in MySQL?

For example, let's say I have a table with the following rows:

score
=====
5
10
20
50
3
15

I'd looking for some type of query along the lines of...

SELECT NUMBER_LIMITER(score, 10) FROM ScoresTable

...which would return the following result...

score
=====
5
10
10
10
3
10

If not, I'll write a function. Just hoping there might be something built-in as performance is quite important for this project. Thanks!

like image 926
LaVache Avatar asked Dec 20 '22 10:12

LaVache


1 Answers

SELECT LEAST(score, 10) FROM ScoresTable

http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html#function_least

like image 60
zerkms Avatar answered Jan 01 '23 11:01

zerkms