Jump to content

[SOLVED] SQL Query MAX


Matrixkid

Recommended Posts

Hi there,

 

I am having trouble getting the results I want from a mysql query.

 

I have this data:

23uzwac.jpg

 

Basically from this data I want the highest value in the 2nd column, so my desired results would be:

Elite Madac | 427 | 100

Elite Sabre  | 512 | 110

 

Instead, I get this:

34qp9q0.jpg

 

This is my sql query:

SELECT idName,max(idAttacks),max(idPoints) FROM stats GROUP BY idName ORDER BY max(idPoints) DESC

 

Thanks for the help!

Cheers

Link to comment
Share on other sites

Thinking it well, you should select only one MAX field. Try this and if it doesn't work, post the table with some data and the column names.

 

SELECT idName, idAttacks, MAX(idPoints) as maxPoints FROM stats GROUP BY idName ORDER BY maxPoints DESC

Link to comment
Share on other sites

yeah, that didnt work either. lol.  >:(

 

Some notes on the table - the query works for all the data except for Elite Mamac, and Elite Sabretooth.

Here is the table:

aud1zr.png

 

here is the result from the last suggest query:

nyfiaw.jpg

 

 

I tried removing the data from Mamac and Sabretooth fields and re-enter them into the DB, and still the problem persists.

But the queries do work for the rest of the data - i am just really confused as to why it isnt working for these two specific ones.

 

Thanks for your help.

Cheers

Link to comment
Share on other sites

That's weird. The query should work there. Select max points/attacks, group the names and order by max points. Nothing special here, so that's really weird. Two quick questions. Are idPoints and idAttacks set as integers in mysql (especially on those 2 guys)? Why do you have repeating records? Generally, it's not a good practice repeating records. You would have to update, delete and insert two fields every time.

Link to comment
Share on other sites

everyday i update the table with the new stats, and i need past stats so i can track the users. is there another way to accomplish this?

 

 

...and...hahaha. it was the integer thing. totally forgot to set the field type. thanks for that pointer. really appreciate your help! +1

 

Link to comment
Share on other sites

Glad it helped.

 

As for the stats, you can expand it even more and have full stats for the users. Have a table stats, with the userid, attacks, points and date and keep everyday records. So you can generate stats not only for the last day, but for the whole registration time (or maybe limit it to 1 month or something). It could need a simple "admin panel" where you can add new stats and old ones are moved automatically to the stats table. Anyway that's you choice :)

 

Cheers.

Link to comment
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.