Jump to content

Recommended Posts

Hi all

 

I have a simple table which looks like

 

ID    USER      PRICE

1    10          12.00

2    21          5.00

3    21          10.00

 

What I want to do is run a query and return all results with the `USER` with the highest value at the top.

 

So with my example above, `USER` ID 10 has a total of 12.00 (ROW 1) and `USER` has a total of 15.00 (5.00 + 10.00) (ROW 2 and 3)

 

So it would therefore return

 

USER  TOTAL

21      15.00

10      12.00

 

Can anyone help?

 

Much love

 

Link to comment
https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/
Share on other sites

Am I seeing things?  I know it doesn't say *edit* but did you switch your SELECT & GROUP BY statements from id to user?  I was just about to post it and I swear it just changed...  ???

 

i did change it...noticed right after i posted...thought i would sneak it in there before anyone caught me :)

Am I seeing things?  I know it doesn't say *edit* but did you switch your SELECT & GROUP BY statements from id to user?  I was just about to post it and I swear it just changed...  ???

 

i did change it...noticed right after i posted...thought i would sneak it in there before anyone caught me :)

 

Hehe, just wanted to make sure I wasn't seeing things.  :o

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.