I have a large table and I want to select 10 random rows in the fast way.
Rows are deleted sometimes, this means i can't random between minId - maxId.
I want different rows without some order.
I tried some code that I found via Google, but this didn't help me. Now I'm using this code:
SELECT `services`.*
FROM `services`
JOIN(
SELECT `serviceId` AS `sid`
FROM `services`
WHERE `services`.`catId` = '{$row["catId"]}' && `subCatId` IS NULL
ORDER BY RAND( )
LIMIT 10
) tmp
LEFT JOIN `cats` ON `services`.`catId` = `cats`.`catId`
WHERE `services`.`catId` = '{$row["catId"]}' && `subCatId` IS NULL && `services`.`serviceId` = `tmp`.`sid`
GROUP BY `services`.`serviceId`
But the page loads slowly
I saw MySQL select 10 random rows from 600K rows fast
It didn't help me.
Thanks a lot