Unix Technical Forum

Invalid Grouping

This is a discussion on Invalid Grouping within the MySQL forums, part of the Database Server Software category; --> Hi, I am having a table with a numeric column where several rows can contain the same value. Now ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:19 AM
Alexander Mueller
 
Posts: n/a
Default Invalid Grouping

Hi,

I am having a table with a numeric column where several rows can contain
the same value. Now I am trying to determine a random value and then to
get a random row from all rows with the next larger value.

Basically I already got it working with the following pseudo code

// Getting a random value between 0 and the maximum value of field
value = SELECT ROUND(RAND()*MAX(field)) FROM table

// Getting the next larger value based on the random value
value2 = SELECT field FROM table WHERE field>value ORDER BY field LIMIT 1

// Getting one random row from all rows with the determined value
row = SELECT * FROM table WHERE field=value2 ORDER BY RAND() LIMIT 1


However I am wondering whether there is a better more efficient way to
achive this.

For example by trying to combine the first two calls into

SELECT field FROM table WHERE field>ROUND(RAND()*MAX(field)) ORDER BY
field LIMIT 1

I am getting an invalid grouping error.

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:57 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com