MySQL: How to get a random string or multiple random strings?

I have a MySQL database table that stores the URLs of photos. I need to pull 5 random records from a database of a specific type. I can pull 5 records:

SELECT Photos.* FROM Photos WHERE Photos.Type_ID = 4 LIMIT 5 

Now I need help trying to figure out how to retrieve different records each time. How can I get random rows from this result set?

+7
source share
3 answers

You can use ORDER BY RAND() to get random strings in your query.

+8
source
 SELECT Photos.* FROM Photos ORDER BY RAND() LIMIT 5 
+6
source

Google points to this detailed page. It looks like it works. I am sure that it cannot provide a separate entry each time , but it is worth a try. http://akinas.com/pages/en/blog/mysql_random_row/

+2
source

All Articles