Posted By

liuran on 12/24/08


Tagged

mysql


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

not_skeletor
warpconduit


get random record from mysql


 / Published in: SQL
 

get some random record from mysql quickly。

  1. SELECT *
  2. FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id) AS t2
  3. WHERE t1.id >= t2.id
  4. ORDER BY t1.id LIMIT 1;

Report this snippet  

You need to login to post a comment.