Reputation: 115
I have 5 INT variables with numbers. I want select one random number from five variables in mysql procedure.
Example data:
DECLARE a, b, c, d, e INT;
SET a = 50;
SET B = 22;
SET C = 88;
SET D = 892;
SET E = 367;
Now I want to select one random number from variables a, b, c, d, e. Any ideas how to do it? Thanks.
Upvotes: 1
Views: 174
Reputation: 2268
SELECT * FROM MyTable ORDER BY RAND() LIMIT 1
UPDATE
SELECT * FROM
(
SELECT @A AS Val
UNION ALL
SELECT @B AS Val
UNION ALL
SELECT @C AS Val
UNION ALL
SELECT @D AS Val
UNION ALL
SELECT @E AS Val
) F
ORDER BY RAND() LIMIT 1
Upvotes: 2