selecting minimum of multiple columns
sql, sql-server, sql-server-2008, t-sql
Solution
Try using `UNION`
SELECT MIN(x.a)
FROM
(
SELECT list1 a FROM table1
UNION
SELECT list2 a FROM table1
UNION
SELECT list3 a FROM table1
) x
UPDATE 1
SELECT ID,MIN(x.a)
FROM
(
SELECT ID,list1 a FROM table1
UNION
SELECT ID,list2 a FROM table1
UNION
SELECT ID,list3 a FROM table1
) x
GROUP BY ID
SQLFiddle Demo
Problem
I have three decimal columns named list1,list2,list3. I want to find the minimum of three in a single query. I've tired this: ``` SELECT Least(list1, list2, list3) FROM table1 ``` It throws an error that `least` is not recognized function.