Slect 1000 rows but only show random 100?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Slect 1000 rows but only show random 100?

Post by alex.barylski »

Is it possible?

I am implementing a tag coud...I have 2000 records alphabetically sorted (and various other ways) but I only want to show 10 or 100 at a time. Obviously using a LIMIT will not work cause I want the output to be random, not alphabetically ordered.

Ideally there is a random aggregate function or something which can jumble my results and I can thus use LIMIT to display only a few.

Make sense? Possible?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Slect 1000 rows but only show random 100?

Post by VladSun »

[sql]SELECT     *FROM     mytableORDER BY    rand()LIMIT     100[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Slect 1000 rows but only show random 100?

Post by alex.barylski »

How did I miss that :oops: :lol:

Thanks again :)
Post Reply