「MySQL入門」RAND()でランダムなデータを作成する方法
方法1
SELECT *
FROM changfatbl AS r1 JOIN
(SELECT ROUND(RAND() *
(SELECT MAX(id)
FROM changfatbl)) AS id)
AS r2
WHERE r1.id >= r2.id
ORDER BY r1.id ASC
LIMIT 5;
方法2
SELECT t1.id
FROM producttbl AS t1 JOIN
(SELECT ROUND(RAND() *
((SELECT MAX(id) FROM itemstbl)-(SELECT MIN(id) FROM itemstbl))+
(SELECT MIN(id) FROM itemstbl)) AS id) AS t2
WHERE t1.id >= t2.id
ORDER BY t1.id LIMIT 0,5;