Hi!
>>>>> "Sinisa" == Sinisa Milivojevic <sinisa@stripped> writes:
Sinisa> Ulf Harnhammar writes:
>> 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.
One way to do this is to do as follows:
SELECT something FROM sometable WHERE somevar=somevalue ORDER BY
RAND() LIMIT 10
>> Perhaps there already is some way to do this efficiently. In that case,
>> please enlighten me.
<cut>
>> 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! ;)
Yes, it was I who wrote that games ages ago...
Regards,
Monty