mysql - SQL selecting X random rows within top Y after ordering -


using mysql, wish select

1) 5 random rows among top 20 rows after ordering "price" column

2) 15 random rows among 30 next results (rows 21-50) after ordering "price" column

what best way achieve performance-wise sql? please note table contains around 1,000,000 rows.

the final purpose update column (set status=1) these randomly selected rows.

use nested selects - should quite fast in situation

select *  ( select .... table  order price limit x, y ) order random 

replace x , y appropriate values

note depending on particular rdbms "order random" , "limit" clauses may differ! mysql way.

the important thing server inner select first, return 20-30 rows (depending on limit clause) , can sort in random order in outer select. if price column indexed fast enough


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -