SET @var = (SELECT FLOOR(RAND() * COUNT(id)) from random); PREPARE statement FROM 'SELECT name FROM random LIMIT ?, 1'; EXECUTE statement USING @var;