The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Random Query Replacement Question
I'm trying to do a random query to pull a random user out of the user table. I want to stay away from the ORDER BY RAND query, if at all possible, as it can be slow on larger tables. Here are the two queries I have come up with so far:
Code:
SELECT userid, username FROM user T JOIN (SELECT FLOOR(MAX(userid)*RAND()) AS ID FROM user) AS x ON T.userid >= x.ID LIMIT 1 SELECT userid, username FROM user T JOIN (SELECT MAX(userid) AS ID FROM user) AS x ON T.userid >= FLOOR(x.ID*RAND()) LIMIT 1; They both seem to run fairly fast but they pull more than one user out of the table. Can anyone tell me where I am screwing up on the LIMIT 1 and which query is actually better than the other for large tables? |
#2
|
|||
|
|||
Quote:
|
#3
|
||||
|
||||
I was using that query in the Run SQL Query area in the Admin CP. You are right, though, that is only returns one result when it is is set as $db->query_read. I would still think the LIMIT 1 should work in the Run SQL Query, though, shouldn't it?
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|