Jump to content

Problems with using DISTINCT


Shadowing

Recommended Posts

Hey guys im having a issue with getting DISTINCT to work

 

im pulling 2 columns using pagination

 

so im counting first and then selecting but it still giving me duplicate owners

 

SELECT COUNT(DISTINCT owner) FROM planets WHERE id != ''

SELECT DISTINCT owner, homes FROM planets WHERE id != '' ORDER BY homes DESC LIMIT $offset, $rowsperpage

Link to comment
Share on other sites

Its a list of planets

 

players own more then one planet

 

each planet has a level of homes on them

 

im trying to grab the players with the highest level of homes in order with out having duplicates.

 

 

so like lets say one player is holding 1st and 2nd place of the highest level of homes I dont want it to grab the 2nd place only the 1st.

 

lol hope that makes sense.

Link to comment
Share on other sites

table2.png

 

that gives me this return

 

I think its correct but its doing it backwards grabing every users lowest amount

 

 

ChristainF: ya i understood you wanted me to write statement but i have no idea :( i couldnt even write it in english so you guys could understand what im trying to do :P hehe

Link to comment
Share on other sites

If all you want is the maximum value for each owner, you would use MAX(homes) as mh, then GROUP BY owner. You would also ORDER BY mh DESC to get the result in the order that you want them.

 

However, if you want the specific row holding the maximum for each owner (perhaps you want the planet name or the row id), you would need to do this - http://dev.mysql.com/doc/refman/5.5/en/example-maximum-column-group-row.html

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.