How to echo random rows from database?

前端 未结 5 752
Happy的楠姐
Happy的楠姐 2020-12-06 22:26

I have a database table with about 160 million rows in it.

The table has two columns: id and listing.

I simply need to used PHP to

5条回答
  •  余生分开走
    2020-12-06 23:00

    If your RAND() function is too slow, and you only need quasi-random records (for a test sample) and not truly random ones, you can always make a fast, effectively-random group by sorting by middle characters (using SUBSTRING) in indexed fields. For example, sorting by the 7th digit of a phone number...in descending order...and then by the 6th digit...in ascending order...that's already quasi-random. You could do the same with character columns: the 6th character in a person's name is going to be meaningless/random, etc.

提交回复
热议问题