文章表
随机栏目下随机取几条符合条件的记录
求高效写法
数据库是mysql的,但是没人回答,到这边试试

解决方案 »

  1.   

    select top 5 * from tb where xx=xx order by newid()
      

  2.   

    try:select top 5 * from tb where 条件 order by newid()
      

  3.   

    SELECT * FROM table_name ORDER BY rand() LIMIT 5;
      

  4.   

    Enter password: ******
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 12
    Server version: 5.5.17 MySQL Community Server (GPL)Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trade of Oracle Corporation and/or its
    affiliates. Other names may be trades of their respective
    owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use test1;
    Database changed
    mysql> SELECT * FROM user ORDER BY rand() LIMIT 5;
    +------+------+
    | id   | name |
    +------+------+
    |    2 | joe  |
    |    5 | ggg  |
    |    6 | vvcc |
    |    6 | vvvv |
    | NULL | cccc |
    +------+------+
    5 rows in set (0.00 sec)mysql>
      

  5.   

    select
     a.* 
    from
     `user` as a
    where
     (select count(1) from `user`  where name >= a.name and id=a.id) <=2
    order by
     rand();