Kryptix Posted December 16, 2009 Share Posted December 16, 2009 Blah, I'm not sure how to do this one but I know as soon as I see the query I'll kick myself. I have two tables, 'experience' and 'player' I need to select the columns 'id' and 'attack' from the first table 'experience' but ONLY if the 'player' table has the column 'on' set to '0' where the 'id' of 'experience' matches the 'id' of 'player' Does that make sense? I'm basically making a highscore list and I need to select the top 20 from 'experience' but only if the player had 'on' set to '0' in his 'player' table where all the settings are stored. Any help would be good. I'm stuck. Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/ Share on other sites More sharing options...
bowett Posted December 16, 2009 Share Posted December 16, 2009 Could you post your table CREATE statements? That way we can more easily visualise what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978395 Share on other sites More sharing options...
cags Posted December 16, 2009 Share Posted December 16, 2009 SELECT id, attack FROM experience JOIN player ON experience.id=player.id WHERE player.on=0 Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978411 Share on other sites More sharing options...
Kryptix Posted December 16, 2009 Author Share Posted December 16, 2009 SELECT id, attack FROM experience JOIN player ON experience.id=player.id WHERE player.on=0 Thanks cags, this is what I have now: SELECT `user`, `exp_attack` FROM `rscd_experience` JOIN `rscd_players` ON `rscd_experience`.`user` = `rscd_players`.`user` WHERE `rscd_players`.`highscores` = '0' #1052 - Column 'user' in field list is ambiguous How do I get around that? Also, how would I also select 'username' and 'owner' from 'rscd_players' from that same record that 'highscores' is in within the same query? Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978688 Share on other sites More sharing options...
cags Posted December 16, 2009 Share Posted December 16, 2009 You probably have to specify the table you wish to take it from, I know it's the same in both tables in this instance so just pick one at random. SELECT rscd_experience.user, exp_attack ... etc. Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978698 Share on other sites More sharing options...
Kryptix Posted December 16, 2009 Author Share Posted December 16, 2009 Thanks mate. This is the query now: SELECT `rscd_players`.`username`, `rscd_players`.`owner`, `rscd_players`.`user`, `rscd_experience`.`exp_attack` FROM `rscd_experience` JOIN `rscd_players` ON `rscd_experience`.`user` = `rscd_players`.`user` WHERE `rscd_players`.`highscores` = '0' ORDER BY `rscd_experience`.`exp_attack` DESC LIMIT 0, 100 This is perfect but it's taking 14 seconds to do the query on localhost. There's 10,000 entries in rscd_players and 10,000 entries in rscd_experience Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978751 Share on other sites More sharing options...
cags Posted December 16, 2009 Share Posted December 16, 2009 Are the user fields set up as indexes? Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978753 Share on other sites More sharing options...
Kryptix Posted December 16, 2009 Author Share Posted December 16, 2009 Are the user fields set up as indexes? In all honesty, I'm not sure what that means. I'm pretty new to MySQL. How would I tell and what does 'indexes' do? Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978779 Share on other sites More sharing options...
Kryptix Posted December 17, 2009 Author Share Posted December 17, 2009 Solved. It was just a ADD INDEX. Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978859 Share on other sites More sharing options...
Kryptix Posted December 17, 2009 Author Share Posted December 17, 2009 Here's what your help produced: http://www.rscemulation.net/highscores.html?highscores=skill_total Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978946 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.