Don P
Don P

Reputation: 63567

SQL - Return minimum value of columns for each row

I need to select the minimum value of 3 columns for each row in a SQL table. The table is thousands of rows. I am using MySQL.

User   val1    val2    val3
1      1       2       5 
2      3       3       3
3      0       1       0

Returns

User    minimum_value
1       1
2       3
3       0

Every search just shows me the MIN() function which is for finding the minim value for an entire column over ALL rows.

Upvotes: 1

Views: 1164

Answers (1)

ntalbs
ntalbs

Reputation: 29438

Perhaps you can use least function:

select least(val1, val2, val3) from your_table;

Upvotes: 2

Related Questions