Post Removed

They have: 8 posts

Joined: Jul 2010

Comment Removed

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Use a subquery:

SELECT * FROM (SELECT * FROM users ORDER BY points DESC LIMIT 3, 50) k ORDER BY RAND()

They have: 8 posts

Joined: Jul 2010

Comment Removed

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Every subquery needs an alias (or name). That "k" is just what I decided to call the subquery.

If you wanted to reference a specific column from that subquery, you would do something like:

SELECT
  k.user_id,  # I am referencing a column from the subquery here
  k.username
FROM
  (SELECT * FROM users ORDER BY points DESC LIMIT 3, 50) k
ORDER BY
  RAND()

If you had two columns named user_id (when you joined with another table), the k would resolve the ambiguity.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.