我想取50随机记录没有重复。
Table Name : table 1
Fields : test_id,test_name,test_phone.
谁能建议我查询,可以获取50个随机记录从数据库没有重复?
尝试:
SELECT DISTINCT * FROM table_1 ORDER BY RAND() LIMIT 50;
确保它们是唯一的,确保test_id
是一个自动递增的INT
使用以下查询
SELECT distinct * FROM `table_1` order by rand() limit 50
。
试试这个
SELECT DISTINCT * FROM table ORDER BY RAND() LIMIT 50
如有疑问请联系。