如何编写一个从数据库中随机选择9行的查询?

时间:2016-08-18 07:18:46

标签: php sql random

SELECT * FROM tbl_specialisation
     WHERE LENGTH(spec_specialise) < 20 ORDER BY spec_specialise LIMIT 9 

添加到此查询

3 个答案:

答案 0 :(得分:0)

USE ORDER BY RAND()

$sql= "SELECT * FROM `tbl_specialisation`WHERE LENGTH(spec_specialise) < 20 ORDER BY RAND() LIMIT 9 ";

答案 1 :(得分:0)

您的问题不明确,因为您要求9个随机字段,但在SQL查询中,您尝试获取9条记录。如果您想从表中获得9条记录,请使用以下内容。

$sql= "SELECT * FROM `tbl_specialisation`WHERE LENGTH(spec_specialise) < 20 ORDER BY RAND() LIMIT 9 ";  

答案 2 :(得分:0)

“SELECT * FROM tbl_specialisation WHERE LENGTH(spec_specialise)&lt; 20 ORDER BY RAND()LIMIT 9”;