Jump to content

Recommended Posts

hey guys ... ia m trying to  select the row with the highest td number

 

SELECT *

FROM `war`

ORDER BY `war`.`td` DESC LIMIT 1

 

But that returns

 

99000

96000

952000

94000

 

instead of

952000

99000

96000

94000

 

Whats wroung? I tryed to sort them from PHPMyADMIN, same problem ...

 

Link to comment
https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/
Share on other sites

Your numbers are stored as Varchar's, thus 99 is > than 95. It does not evaluate the actual numbers.

 

Store them as int's and the problem should be solved :)

 

EDIT:

That's twice today rhod, I would highly suggest not doing that again  >:(  >:D

SELECT * FROM `war` ORDER BY `war`. `MAX(td)` DESC LIMIT 1

 

I'm unfamiliary with putting the tildes there, why do you do that?

 

That would not work, due to the max being in the wrong place and that his table structure is most likely varchar for "td".

 

The ` are used around table, db and column names to signify them as such. They are not required and do not hurt to be there. To correct your SQL (just to show you the proper way) here it is:

SELECT * FROM `war` ORDER BY MAX(`war`. `td`) DESC LIMIT 1

 

But I doubt that would work, cause MAX is for the select portion and needs/requires a group by. Group By Aggregate Functions

 

For a tutorial on MAX go here.

SELECT * FROM `war` ORDER BY `war`. `MAX(td)` DESC LIMIT 1

 

I'm unfamiliary with putting the tildes there, why do you do that?

 

That would not work, due to the max being in the wrong place and that his table structure is most likely varchar for "td".

 

The ` are used around table, db and column names to signify them as such. They are not required and do not hurt to be there. To correct your SQL (just to show you the proper way) here it is:

SELECT * FROM `war` ORDER BY MAX(`war`. `td`) DESC LIMIT 1

 

But I doubt that would work, cause MAX is for the select portion and needs/requires a group by. Group By Aggregate Functions

 

For a tutorial on MAX go here.

 

 

You are a guru aren't you!!!!

 

 

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.