I have apparently simple query:
SELECT tag_id
from books_tags
WHERE tag_id IN (SELECT tag_id
FROM books_tags
GROUP BY tag_id
ORDER BY COUNT(tag_id) DESC
LIMIT 100)
ORDER BY RAND()
LIMIT 1
I wish to select one random record from query inside. It does not work, error says that LIMIT and ORDER cannot appear in subquery.
I dont wanna create temporary table, or random on servers side. Any ideas how to merge it into wone query?