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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.