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.
teammatt3 posted this at 18:30 — 3rd January 2011.
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()
shaunno2009 posted this at 11:11 — 3rd April 2021.
They have: 8 posts
Joined: Jul 2010
Comment Removed
teammatt3 posted this at 00:08 — 4th January 2011.
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.