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 -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -