List:General Discussion« Previous MessageNext Message »
From:Christian Meisinger Date:April 27 2005 7:13am
Subject:Re: Get a Random Row on a HUGE db
View as plain text  
> $last_row ="SELECT from firebase_content LAST_INSERT_ID()";
> $last_row_query = $dbi->query($last_row);
> $last_row_result = $row->id;

i think LAST_INSERT_ID will not work for what you wonna do.
if you open a connection to MySQL and call LAST_INSERT_ID without a
INSERT it will return 0.

http://dev.mysql.com/doc/mysql/en/getting-unique-id.html

" For LAST_INSERT_ID(), the most recently generated ID is maintained
in the server on a per-connection basis. "

so it would work if you have only ONE connection for all INSERTs and
your SELECT.


i think you have to get the highest id first and then select a
random row.

instead of SELECT MAX() try
SELECT `id` FROM `whatever` ORDER BY `id` DESC LIMIT 1;

i tried this and it's faster then MAX().

ORDER BY RAND() seems to be the slowest method.


	chris
Thread
Get a Random Row on a HUGE dbgunmuse26 Apr
  • Re: Get a Random Row on a HUGE dbRhino26 Apr
  • Re: Get a Random Row on a HUGE dbDawid Kuroczko27 Apr
RE: Get a Random Row on a HUGE dbJay Blanchard26 Apr
  • RE: Get a Random Row on a HUGE dbgunmuse26 Apr
    • Re: Get a Random Row on a HUGE dbPeter Brawley26 Apr
      • RE: Get a Random Row on a HUGE dbgunmuse26 Apr
      • RE: Get a Random Row on a HUGE dbgunmuse26 Apr
        • Re: Get a Random Row on a HUGE dbGary Richardson27 Apr
    • Re: Get a Random Row on a HUGE dbChristian Meisinger27 Apr
    • Re: Get a Random Row on a HUGE dbScott Gifford27 Apr
    • Re: Get a Random Row on a HUGE dbJigal van Hemert28 Apr