Jump to content
php.lv forumi

select + random


cucumber

Recommended Posts

Vai ir iespejams, ar mysql palidzibu no tabulas panemt 10 pedejos ierakstus un tad no tiem 10 panmetiem 4 random'a?

SELECT * FROM `table` ORDER BY `id` desc limit 10 // pedejie desmit
SELECT * FROM `table` ORDER BY RAND() limit 4 // randoms

Edited by cucumber
Link to comment
Share on other sites

SELECT * FROM tabula WHERE id IN (SELECT id FROM tabula ORDER BY id LIMIT 10) ORDER BY RND() LIMIT 4

 

Shitos variantus es jau meginaju un "kombineju" , bet neko pratigaku par #1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' nebiju dabujis.

 

ps. Uztaisiju ta ka ar pirmo query uztaisas temp tabula un ar otro query 4 randuma no temp tabulas panem , cik labi ta ir darit?

Link to comment
Share on other sites

Default engine as of MySQL 3.23 with great performance Viss skaidrs (:

Link to comment
Share on other sites

ta var, bet gribejas iztikt ar mysql pusi.

Link to comment
Share on other sites

×
×
  • Create New...