galvin Posted February 9, 2009 Share Posted February 9, 2009 My tables have more fields than this, but I will only list the ones that apply to this problem... TABLE 1 (called "runningbacks"): playerid, teamid TABLE 2 (called "opponents"): teamid, week1opp Before TABLE 2 came into the mix, I had the following MySQL query... $sql = "SELECT playerid, teamid FROM runningbacks; Simple enough, but now I need to expand on that query to also look to this other table called "opponents" and bring back the proper value for "week1opp" based on the the teamid (for EVERY single playerID that it brings back)... So, for example, let's say "runningbacks" had the following info... playerid/teamid 1001/3 1002/6 1003/5 1004/5 1005/19 1006/6 etc, etc.... And let's say table "opponents" had... teamid/week1opp 1/Raiders 2/Saints 3/Cowboys 4/Ravens 5/Steelers 6/Cardinals etc, etc. I need the query to find that for playerid 1001, the "week1opp" is "Cowboys"....for playerid 1002, the "week1opp" is "Cardinals" and so on. I believe this is simple but I'm having trouble. Can anyone help?... Quote Link to comment https://forums.phpfreaks.com/topic/144416-solved-need-help-with-pulling-data-from-two-tables/ Share on other sites More sharing options...
peranha Posted February 9, 2009 Share Posted February 9, 2009 $sql = "SELECT RB.playerid, RB.teamid, O.week1opp FROM runningbacks RB INNER JOIN opponents O ON RB.teamid = O.teamid; try that and see what you get. Quote Link to comment https://forums.phpfreaks.com/topic/144416-solved-need-help-with-pulling-data-from-two-tables/#findComment-757838 Share on other sites More sharing options...
galvin Posted February 9, 2009 Author Share Posted February 9, 2009 That did it! Thanks very much!!! Quote Link to comment https://forums.phpfreaks.com/topic/144416-solved-need-help-with-pulling-data-from-two-tables/#findComment-757841 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.