-1

i would like to know if there is a ny way one could select random rows (i have six in mind) from a mysql server without any of the results repeating itself. I know of the Rand() function in selecting random rows.

Cœur
  • 37,241
  • 25
  • 195
  • 267
jcobhams
  • 796
  • 2
  • 12
  • 29

1 Answers1

2

SELECT * FROM table ORDER BY RAND() LIMIT 6;

But also have a look at http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/ to understand that this can cause problems with large tables.

Shi
  • 4,178
  • 1
  • 26
  • 31
  • thanks but this affect my site performance...is there a better way to go about this? – jcobhams Aug 19 '12 at 19:11
  • @VyrenMedia: Did you already read the link for another idea? And without a table schema, we can just guess. – Shi Aug 19 '12 at 19:13
  • i jus visited the link you sent me....its not well explanatory...It just say bits and bits of code without giving one complete code to work with...Thank for it anyways...if yo have another link please sent it or better still if you have a working code please send it over. – jcobhams Aug 19 '12 at 19:20