I have around 300 records in some table in mysql database. And I have a requirement to fetch 40 random records with one query. How to write the query?
need help
thanks.
I have around 300 records in some table in mysql database. And I have
Share
For a small table likes yours it should suffice with this:
Note that this is not suitable for large tables since MySQL will have to do a table scan and order all rows in the table due to the usage of
ORDER BY RAND(). For large tables you will have to implement this mostly in application code, keeping track of which rows you’ve already got and generating random ids to fetch.