Jump to content

Recommended Posts

Okay, to try explain the problem, I think I should first show the tables:

 

Score Table:

	ScoreID	GameID	BoardID	UserID	Score

 

Leaderboard table:

No	ID	GameID	BoardID	Title	DataType	Sort	ScoreLabel

 

Game Table:

	ID	GameName	GameSlug	GameDesc	GameW	GameH	GameFile	GameThum	GameCat	ScoreEnabled	DateAdded

 

 

Okay the tables look a bit messy, and yes, I do need 3 tables (I'm using external API's so I have to make sense of the data as best as I can).

 

Now the problem lies when I'm trying to extract the highscores. Once again, heres the current SQL I've managed to write up with my little knowledge and a lot of googleing:

			// get query
			$query = "SELECT * FROM scores, games, leaderboard ";
			$query.= "WHERE scores.GameID = leaderboard.GameID ";
			$query.= "AND leaderboard.ID = games.ID ";
			$query .= "ORDER BY ScoreID DESC";
			$query .= " LIMIT 10";

 

This displays all the records, and with PHP I can display everything about every highscore recorded.

Now what I'm trying to get the SQL to do is only display the highest score from all the games.

 

I'm aware I can do that in PHP, storing every field in array, and then after processing it, but I was hoping it can be done in MYSQL itself. I've half had the max (fieldname) work in previous examples, but that output just the highest score from all games (regardless how many games they are, only 1 highscore is output). I've stumbled onto the DISTINCT function, but havn't got that to work (e.g. $query.= "AND (SELECT DISTINCT FROM scores.GameID) "; ) . I don't know if thats the right way to use it, but I havn't found a decent tutorial explaining how I can use that within the other statement.

 

Can anyone point me in the right direction? I'm sorry if this is a bit confusing, and if needed Ill try explain in more detail.

And before I forget, I'm using the version : 5.0.91-community-log

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/216321-pulling-unique-records/
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.