开发者

Mysql random rows from all values of another table

I have Table A with 15,000 rows each having a unique ID and Table B with 10,000,000 rows with multiple rows for each unique ID in Table A. I need to check Table B for each ID from Table A and select 1 random row from each of all matching IDs. So once the query runs I will end up with 15,000 random rows from Table B (each with a unique Table A ID).

I'd assume this is too intense for RAND() alone or a lo开发者_高级运维op so it's got to be an involved select.

Looked to this but it only involves one table http://explainextended.com/2009/03/01/selecting-random-rows/

Not able to adjust it to do what I need.


what about something like this?

select distinct b.a_id from b inner join a on a.id = b.id order by rand(10000000)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜