Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/185323-query-help/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978688
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/185323-query-help/#findComment-978751
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.