List:General Discussion« Previous MessageNext Message »
From:Ulf Harnhammar Date:January 23 2002 4:08pm
Subject:Using LIMIT to select random rows
View as plain text  
This is a suggestion for a small addition to MySQL's syntax which I'm
proposing, unless someone is kind enough to show me that there already is
equivalent functionality somewhere else in MySQL.

See, what I want to do is select a few random rows among those that
normally would be returned. I don't want to select all matching ID's in
one select, retrieve them to my script, and then construct another SELECT,
because this seems to be slow. I don't want to use lots of "SELECT
something FROM sometable LIMIT number,1" statements either, because this
seems to be slow too.

I propose this additional syntax to Monty and the guys:
SELECT something FROM sometable WHERE somevar=somevalue
LIMIT number1,1,number2,1,number3,1,..
which should return the rows numbered "number1", "number2", "number3" etc
from the rows that normally would be returned. This way, I could first use
a "SELECT COUNT(*) FROM sometable WHERE somevar=somevalue" statement, and
then issue another statement of the kind that I propose, to get a few
random rows.

Perhaps there already is some way to do this efficiently. In that case,
please enlighten me.

Regards, Ulf Härnhammar

PS: Talking about Monty, is he by any chance the same Monty who was in a
team called Monty & Kaj and wrote a PacMan clone called Blipp for the
ABC80 computer decades ago? Man, that game was cool! ;)

________________________________________
Ulf Härnhammar
System Developer

ST-Registry
St Eriksgatan 117, E2
SE-113 43 Stockholm
SWEDEN (GMT+1)

Telephone:	+46 (0)8-545 476 04
Facsimile:	+46 (0)8-32 63 33

E-mail:	ulf@stripped
Web: http://www.nic.st/

The STreet domain - your Internet address

Thread
Using LIMIT to select random rowsUlf Harnhammar23 Jan
  • Re: Using LIMIT to select random rowsSinisa Milivojevic23 Jan
    • Re: Using LIMIT to select random rowsMichael Widenius27 Jan
      • Re: Using LIMIT to select random rowsUlf Harnhammar29 Jan
        • Re: Using LIMIT to select random rowsMichael Widenius29 Jan
          • Using RAND()GNAPs)7 May
            • RE: Using RAND()Gurhan Ozen7 May
              • Re: Using RAND()webmaster7 May
                • RE: Using RAND()Gurhan Ozen7 May
            • Re: Using RAND()Paul DuBois7 May
  • RE: Using LIMIT to select random rowsGordon29 Jan
RE: Using LIMIT to select random rowsSteven Lagerweij23 Jan