Thanks for the answers, I still have a few questions about how the query is actually executed.
Say I have a query that says:
SELECT * FROM tbl_gallery WHERE fld_userid = $UserID ORDER BY RAND() LIMIT 4
I understand (from what I've read) that the database will shuffle the rows and select 4 at random, but will the WHERE clause be executed first? Would it pick the rows that meet the where criteria and then shuffle them and select the 4 or does it shuffle all the rows and select 4 and then check the where clause?