order by with random in between in mysql -


i have query this.

select * test order rank 

enter image description here

this query displaying record order rank. now, have rank column range 1 500000. , want query displaying record 100000 in rank column display old query , 100000 400000 they should display randomly , 400000 500000 old query. tried this.

(select * `test` `rank` <= 100000 order `rank`) union (select * `test` `rank` > 100000 , `rank` <= 400000 order rand()) union (select * `test` `rank` > 400000 order `rank`) 

but display want rendom between rank column 100000 400000.

enter image description here

so need write 2 select statements, combined union:

-- display ordered way till 100000 select * `test` `rank` <= 100000 order `rank` --- join it. union -- display random way after 400000 select * `test` `rank` > 100000 , `rank` <= 400000 order rand() -- join it. union -- display ordered way till 400000 select * `test` `rank` > 400000 order `rank` 

ultimately, display records, thing is, first 400000 records displayed in ascending order, , next random.

fiddle: http://sqlfiddle.com/#!9/7521d/2


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -