Andy Booth Posted January 23, 2007 Share Posted January 23, 2007 Ok, i'll try explain this the best way I can.......SELECT users.user_name, games.game_name, games.game_console, offer.game1_id, offer.game2_id, offer.game3_id, offer.game4_id, offer.game5_id, offer.all_games, offer.secure, offer.status, owned.game_id, owned.master_id FROM users, games, offer, owned WHERE (users.master_id = '2') AND (offer.user_id = '2') AND (owned.game_id = games.game_id).The 'owned.master_id' has a different value to the value I have specified as being '2' for the users.master_id. The thing is, I want to get the username (from the users table) for the member whos master id is owned.master_id. Can I do this all in one query? I want it along with everything else i've already successfully retrieved..Thanks :) Quote Link to comment Share on other sites More sharing options...
fenway Posted January 23, 2007 Share Posted January 23, 2007 You sure you're not missing join conditions here? And I'm not sure I understand why you just can included an OR. Quote Link to comment Share on other sites More sharing options...
Andy Booth Posted January 23, 2007 Author Share Posted January 23, 2007 I'm sorry, im fairly new to MySQL and databases as a whole...The statement I have put there works as it is, but I just want to add that one field to it?Hope someone can help? :) Quote Link to comment Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 What other conditions are satisfied for that 'one field', as you call it? Quote Link to comment Share on other sites More sharing options...
Andy Booth Posted January 24, 2007 Author Share Posted January 24, 2007 I'm not sure what you mean exactly...so i'll try explain the whole situation...I want a query that will do the following.Retrieve records from a table called offer. I want to retrieve games.game_name and games.game_console using the offer.game_id which links to games.game_id. From the offer table also contains the master_id of the member the offer is being offered to. I want to get the user_name of that master_id which can be found in the users table.Does this help? :) Quote Link to comment Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 So should it be:[code]SELECT g.game_name, g.game_console, u.user_nameFROM offer AS oLEFT JOIN games AS g ON ( g.game_id = o.game_id )LEFT JOIN users AS u ON ( u.master_id = o.master_id )[/code] Quote Link to comment Share on other sites More sharing options...
Andy Booth Posted January 24, 2007 Author Share Posted January 24, 2007 I think im getting it sorted now, many thanks :) ;D 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.