MYSQL select random of each of the categories -


i want select random 5 records each categories in same table.

table name: t_shop

column name: shop_id, shop_categoryid

for example: shop_id | shop_categoryid

1 | 1 2 | 1 5 | 1 7 | 1 9 | 1 10| 1 13| 2 15| 2 22| 2 23| 2 25| 2 

i have tried using limit in subquery, error occur: version of mysql doesn't yet support 'limit & in/all/any/some subquery

i ask there ways solve? thanks.

if have 2 categories (as in question), easiest way in mysql use union all:

(select * t_shop category = 1 order rand() limit 5) union (select * t_shop category = 2 order rand() limit 5) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -