Staggan Posted November 29, 2012 Share Posted November 29, 2012 Hello I am trying to get data from another table added into my query to save using another query... here is my current query: SELECT * from challenge where challenge_id = $challengeid AND status = 'completed' || status = 'forfeit' I would like to add name from the team table where team_id = challenge.winner_team_id How would I do this... I am sure it is some kind of join, but when I tried I could not get the name field in my result Any help would be much appreciated Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted November 29, 2012 Share Posted November 29, 2012 SELECT * from challenge INNER JOIN team ON team.team_id = challenge.winner_team_id where challenge_id = $challengeid AND (status = 'completed' OR status = 'forfeit') Quote Link to comment Share on other sites More sharing options...
Staggan Posted November 29, 2012 Author Share Posted November 29, 2012 Hello, That does what I want, but I need to change it slightly... If challenge.winner_team_id is -1 I still need the results but need to set team.name = -1 So I need.. Everything from challenges based on status, and then IF winner_team_id exists in team table I need name, or I need to set name = -1 Can this be done? Thanks Quote Link to comment Share on other sites More sharing options...
Staggan Posted November 29, 2012 Author Share Posted November 29, 2012 Ah, LEFT JOIN gave me what I needed instead of INNER JOIN, it set the name field to NULL which I can test for Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.