sql - Using MYSQL GROUP_CONCAT with sub query -
i trying head around using group_concat within mysql.
basically have following table, table1:
id, field1, field2, active
i want bring 5 rows within table in random order. i'm using this:
select group_concat(id order rand()) table1 active=1
this behaves expect. want use output select other columns (field1, field2) table , display results. i've tried using:
select * table1 id in ( select group_concat(id order rand()) id table1 active=1 );
i expected above work cant figure out why doesn't. bring results not of them, (i.e.) table contains 10 rows. 6 rows set active=1. therefore expect 6 rows returned ... isn't happening may 1,2 or 0.
additionally if helps i'd limit number of results returned sub-query 3 adding limit doesn't seem have affect on results returned.
thank in advance
i think looking for. bring 5 random active rows.
select * table1 active=1 order rand() limit 5;
Comments
Post a Comment