Jump to content

Expert Advice needed about rand() in mysql


karthikeyan_coder

Recommended Posts

Hello,
        i want to get some random rows from my table.. here is the query

[code]$ sql = "SELECT * FROM `banner` WHERE `AID`='1' AND `ACTIVE`='Y' ORDER BY rand() LIMIT 0,2";[/code]
it is for getting two rows... is this will give me different two rows always?? coz im expecting some problems occationally, it gives less no of rows... it may be a problem with rest of my code.. but what do you think about rand() in the mysql query?

Thank you.
Link to comment
https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/
Share on other sites

In what sense do u want to know if u can trust it..I have used a similar query and it has worked for me. However, when the database is small it seems to be less worthwhile. Other than this approach u can always shuffle the mysql fetch array results and output two random entries. But rand works best.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.