sql - Trouble with having a subquery with INNER JOIN -


i'm having trouble trying use subquery inner join.

in code below, average rating i'm trying compute needs average rating of player (a.player).

from looking @ script below, my questions are:

1) should nest subquery when using inner join?

2) there 20 names in table i'm pulling information (table 'college'). in subquery need 'b.rating' specific player. need clause in subquery, "where player=a.player"?

$query = "select a.player,a.team,a.loc,a.pic,a.rank,b.rating college         join (select avg(rating) rating college_rating) b         on a.player=b.player         order rank desc limit 20"; $run = mysqli_query($link,$query); while($row = mysqli_fetch_array($run)) { echo $row['player'] . ' ' . $row['rating'] . ' ' . $row['team'] . '<br>'; } 

you need find average rating each palyer in subquery shown below

$query = "select a.player,a.team,a.loc,a.pic,a.rank,b.rating college           join (                 select player,avg(rating) rating                  college_rating                 group player                ) b         on a.player=b.player         order rank desc limit 20"; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -