| 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 db | gunmuse | 26 Apr |
| • Re: Get a Random Row on a HUGE db | Rhino | 26 Apr |
| • Re: Get a Random Row on a HUGE db | Dawid Kuroczko | 27 Apr |
| • RE: Get a Random Row on a HUGE db | Jay Blanchard | 26 Apr |
| • RE: Get a Random Row on a HUGE db | gunmuse | 26 Apr |
| • Re: Get a Random Row on a HUGE db | Peter Brawley | 26 Apr |
| • RE: Get a Random Row on a HUGE db | gunmuse | 26 Apr |
| • RE: Get a Random Row on a HUGE db | gunmuse | 26 Apr |
| • Re: Get a Random Row on a HUGE db | Gary Richardson | 27 Apr |
| • Re: Get a Random Row on a HUGE db | Christian Meisinger | 27 Apr |
| • Re: Get a Random Row on a HUGE db | Scott Gifford | 27 Apr |
| • Re: Get a Random Row on a HUGE db | Jigal van Hemert | 28 Apr |
