I need a faster alternative for
SELECT *
FROM table
WHERE cat='catname'
ORDER BY RAND() LIMIT 6
I need a faster alternative for
SELECT *
FROM table
WHERE cat='catname'
ORDER BY RAND() LIMIT 6
If the table is very big, shuffling inside your application could be very slow.
What about this solution:
Find out the size of the table (how many rows). than, programmatically find 6 random numbers between 0 and number_of_rows
.
The second query for searching the rows:
select * from table where id = id1 or id = id2...
The faster way is don't use RAND()
in your query. Shuffle your results inside your application.