karthikeyan_coder Posted October 31, 2006 Share Posted October 31, 2006 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. Quote Link to comment Share on other sites More sharing options...
scliburn Posted October 31, 2006 Share Posted October 31, 2006 um, try LIMIT 2calling to the initial offset may give you a hassle. KISS - [b]K[/b]eep [b]I[/b]t [b]S[/b]imple and [b]S[/b]tupid. ;D Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted October 31, 2006 Author Share Posted October 31, 2006 Ohh... ok.. What about rand() .. Can we trust it? Quote Link to comment Share on other sites More sharing options...
oracle259 Posted October 31, 2006 Share Posted October 31, 2006 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 31, 2006 Share Posted October 31, 2006 If the number of records matching your WHERE criteria is less than your limit then that's all you'll get Quote Link to comment Share on other sites More sharing options...
scliburn Posted October 31, 2006 Share Posted October 31, 2006 i've been able trust it. having 1.5 million entries in a table helps the rand() ideals. ;) Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted October 31, 2006 Author Share Posted October 31, 2006 Ok Thank you Scliburn,Barry Andrew and Oracle :) just back to development with rand(); :) Quote Link to comment Share on other sites More sharing options...
Barand Posted October 31, 2006 Share Posted October 31, 2006 omg, my secret identity has been blown :o Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.