mysql随机返回记录
The ability to return random records from a MySQL table is invaluable. Returning random records is helpful when:
从MySQL表返回随机记录的能力非常宝贵。 在以下情况下,返回随机记录将很有帮助:
- featuring items without showing favoritism to one 特色商品,不显示偏爱
- testing different result sets in your PHP 在您PHP中测试不同的结果集
- looking to display specific items in a non-specific order 希望以非特定顺序显示特定项目
The great part about selecting random records from your MySQL tables is that it's really easy.
从MySQL表中选择随机记录的重要之处在于,这很容易。
代码 (The Code)
SELECT product_id, title, description
FROM products
WHERE active = 1
AND stock > 0
ORDER BY RAND()
LIMIT 4
The ORDER BY RAND()
clause returns random records!
ORDER BY RAND()
子句返回随机记录!
mysql随机返回记录