php - MySQL Random Result Group By Order By -


how random result on group by group_id?

its similar this: random order group of rows in mysql

here fiddle: http://sqlfiddle.com/#!9/1c73d/3

not sure why gives me same result.

create table job     (`job_id` int, `group_id` int, `user_id` int, `title` varchar(50), `description` varchar(55), `type` tinyint) ;  insert job     (`job_id`, `group_id`, `user_id`, `title`, `description`,`type`) values     (1, 1, 100, 'title 1', 'text 1', 1),     (2, 1, 100, 'title 2', 'text 2', 1),     (3, 1, 200, 'title 3', 'text 3', 1),     (4, 1, 200, 'title 4', 'text 4', 1),     (5, 1, 300, 'title 5', 'text 5', 2),     (6, 1, 400, 'title 6', 'text 6', 1),     (7, 1, 200, 'title 7', 'text 7', 1); 

query:

select * job     type = 1     group group_id     order rand() 

assuming want 1 random record each group under type = 1:

select  *  (     select         *     job     type = 1     order rand() ) t group t.group_id; 

sql fiddle demo


Comments

Popular posts from this blog

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -