I have this SQL query, and directly under it, another query based on the result.
I’d like to merge them, but im getting confused, being a newbie.
It’s pulling data from 3 tables- the first query from the USERS and the PLAYERS table. Then if the player is in a ‘team’, it gets the tag from the TEAMS table.
My code:
$sql_result4=mysql_query("SELECT * FROM users JOIN players ON users.player=players.name WHERE users.id='$id'");
$rs4 = mysql_fetch_array($sql_result4);
if ($rs4[team] !=0) {
$sql_result = mysql_query("SELECT tag FROM teams WHERE id='$rs4[team]'", $db);
$rs = mysql_fetch_array($sql_result);
// get data
}
My question is, how could i merge that second query in with the first? Am I even using the right kind of join?
I want to be able to use lots of data from the PLAYERS table, but only one or two columns from the USERS and TEAMS ones.
Just use a left join.