I have a table set up as the following
ID COL1 COL2 COL3
----------------
10 200 n/a 125
11 150 130 n/a
12 100 300 200
13 500 n/a n/a
I suspect using LEAST
will result in table scans. You may want to break it down manually (obviously, I expect indexes to be present on COL1
, COL2
and COL3
):
SELECT ID, VALUE FROM (
SELECT ID, COL1 AS VALUE FROM MYTABLE ORDER BY COL1 ASC LIMIT 1
UNION
SELECT ID, COL2 AS VALUE FROM MYTABLE ORDER BY COL2 ASC LIMIT 1
UNION
SELECT ID, COL3 AS VALUE FROM MYTABLE ORDER BY COL3 ASC LIMIT 1
) ORDER BY VALUE ASC LIMIT 1