I'm trying to ORDER BY a MYSQL query correctly. I need the rand() to include the query with the shortest length, the query with the second shortest length, and the query with the third shortest length. Is there a way to do that with just MYSQL?
SELECT input FROM tableName WHERE input LIKE '%one%' ORDER BY length(input) ASC, rand() limit 1;
one
one one
one one one
one one one one
In this case, the query only include the rand() with the lowest length. So basically, I need the rand() to include the:
one
one one
one one one
So that it selects one of these randomly.
order by length(input) asc limit 3;
It will return
one
one one
one one one