php - Returning random rows from mysql database without using rand() -


I would like to be able to pull 15 or more records from the database I have seen that WHERE id = rand () Performance problems can be caused by using because my database gets bigger I have seen that all the solutions are ready to select a random record.

Edit:

Edit Further Read More:

On a new database using MySam I Simple table is created. I gave this 3 fields: autokey (unsigned auto number key) bigdata (a big blob) and somemore (a medium int). I re-applied the random data table and ran a series of queries using Navicat. Here are the results:

Question 1: rand () range 15)

  Question 2: * join the test Select (select round (rand) * * maximum (test autocomplete)) as rows on rnd.val = rt. Test.autokey;  

(I tried to select both and select different and did not find any difference)

and:

 < Code> Question 3 (I only ran in the second test): SELECT * FROM (SELECT @cnt: = test (*) + 1, @lim: test from 10) vars STREIGHT_JOIN (SELECT r. *, @lim: = @lim - 1 test r WHERE (@cnt: = @ cnt-1) and rand (20030101)  @lim / @cnt) I  
 Rosa: Question 1 : Question 2: Question 3: 2,060 9 22 2. 9 77 S 0.002 SN / A3,043,406 5.334 s 0.001s 1.260 

I would like to make more lines, so I can see OE query to 3 scales, but this time, It looks like the clear winner query 2 is.

Before I wrap this test and declare an answer, and whenever I have this figure and the test environment is established, can someone else do the test ?

Try:

  select * rand By the table order (), the limit 15  

must be linked to a set of random values ​​in another (and possibly more efficiently) manner. This should work, if there is some consolidated integer key in the table PostGrace (My MySQL is a bit wild) How do I do this

  Include in the selection * Table Connect to (Select (Random; * * maxid) :: Gener_series (1,15) as the integer in the form of rand.val = rnd; table at .and;  

Where maxid is the id in the highest id if there is an index of id , it means only 15 index lookups So its intensity.

UPDATE :

It seems that there is no such thing as gener_series in MySQL. We really need it Do not: Join

  Select Table - It returns only 15 random numbers - I need only `table` to create rows for table range (maximum of table Select more than (ID) (Round ()) (Maximum to 15 in table form) Id as rnd on rnd.val = table;  

PS If I do not want to return to duplicate, then I can select different ([...] in random generator expression .


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -