Mysql RAND() functionatility

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
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Mysql RAND() functionatility

Post by Nunners »

I have a mysql statement which produces a list of accommodation within a certain area. Within the list, they are sorted by Accommodation type, and rating. Once at that level, I want the list to be sorted randomly - and different each time.

My current sql statement is:

Code: Select all

select list of fields required from 2 tables where various statements ORDER BY ACCOM_TYPE ASC, RATING DESC, RAND()
How does the RAND() behave? I've seen somewhere that it is not very efficient, particularly with large lists.
Has anyone else got any experience of trying to randomise large lists, and done it efficiently and successfully?

Cheers
Nunners
Post Reply