almo2001

Why does this work.

Apr 19th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.95 KB | None | 0 0
  1. How does it know which userid to use on the lw and lm selects? They are foreign keys to the same table, ld_users.
  2.  
  3. SELECT us.points as userscore,
  4.        us.rank as userrank,
  5.        lw.points as userscoreweekly,
  6.        lw.rank as userrankweekly,
  7.        lm.points as userscoremonthly,
  8.        lm.rank as userrankmonthly
  9.   FROM ld_user_scores as us,
  10.        ld_leaderboard_weekly as lw,
  11.        ld_leaderboard_monthly as lm
  12.  WHERE us.userid = 50
  13.  
  14. How it should be done:
  15.  
  16.           SELECT us.points as userscore,
  17.                  us.rank as userrank,
  18.                  lw.points as userscoreweekly,
  19.                  lw.rank as userrankweekly,
  20.                  lm.points as userscoremonthly,
  21.                  lm.rank as userrankmonthly
  22.           FROM ld_user_scores as us
  23.           INNER JOIN ld_leaderboard_weekly as lw ON us.userid = lw.userid
  24.           INNER JOIN ld_leaderboard_monthly as lm ON us.userid = lm.userid
  25.           WHERE us.userid = $userid
Advertisement
Add Comment
Please, Sign In to add comment