i have table different categories. possible return 2 random rows each category?
my table:
----------------------------- | id | category | ----------------------------- | 1 | pink | | 2 | green | | 3 | pink | | 4 | green | | 5 | blue | | 6 | blue | | 7 | blue | | 8 | pink | | 9 | green | ----------------------------- what want output:
----------------------------- | id | category | ----------------------------- | 1 | pink | | 8 | pink | | 2 | green | | 4 | green | | 6 | blue | | 7 | blue | -----------------------------
select distinct c1.id, c2.category mytable c1 join mytable c2 on c1.category = c2.category , c1.id <> c2.id group c1.category, c2.id;
Comments
Post a Comment