我想創建一個索引頁面,其中包含字母表中每個字母的幾個結果。有一種性能友好的方式來列出數據庫中每個字母的結果嗎?
目前,我有這樣的:
SELECT url_slug, name FROM artists WHERE name LIKE "A%" ORDER BY rand() LIMIT 10
SELECT url_slug, name FROM artists WHERE name LIKE "B%" ORDER BY rand() LIMIT 10
SELECT url_slug, name FROM artists WHERE name LIKE "C%" ORDER BY rand() LIMIT 10
SELECT url_slug, name FROM artists WHERE name LIKE "D%" ORDER BY rand() LIMIT 10
SELECT url_slug, name FROM artists WHERE name LIKE "E%" ORDER BY rand() LIMIT 10
SELECT url_slug, name FROM artists WHERE name LIKE "F%" ORDER BY rand() LIMIT 10
有另一種,更表現友好,辦法實現這一目標?
P.s.我知道'rand()'的順序不是很好。但這只是在開發中。
是'name'列索引?如果不是這應該有很大幫助。 – 2012-04-10 23:34:27
是的。我目前沒有任何性能問題..但選擇26次似乎是錯誤的,因此我的問題;這可以通過其他方式完成嗎? – 2012-04-10 23:36:33