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. Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/ 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 Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/#findComment-117431 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? Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/#findComment-117475 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. Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/#findComment-117493 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 Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/#findComment-117504 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. ;) Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/#findComment-117507 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(); :) Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/#findComment-117519 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 Link to comment https://forums.phpfreaks.com/topic/25728-expert-advice-needed-about-rand-in-mysql/#findComment-117523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.