0

I want that i random 5 data from my table but i want that the value "orange" is always displayed in this random and "orange" also rand with them , sow how to do that?

select fruits from table ORDER BY rand() limit 5;
1
  • Tag your question with the database you are using. Commented Dec 25, 2018 at 20:20

2 Answers 2

1

You can select orange separately:

(select fruits from table where name = 'orange')
union all
(select fruits from table where name <> 'orange' order by rand() limit 4)
order by rand()
2
  • thanks bro but i want that my orange word olso rand with them @Salman A Commented Dec 25, 2018 at 20:16
  • the second rand() shuffles its position. Commented Dec 25, 2018 at 20:23
0

You can do this using:

select t.fruits
from table t
order by (case when t.fruit = 'orange' then 1 else 2 end),
      rand()
limit 5;

Not the answer you're looking for? Browse other questions tagged or ask your own question.