drisate Posted February 20, 2009 Share Posted February 20, 2009 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/ Share on other sites More sharing options...
rhodesa Posted February 20, 2009 Share Posted February 20, 2009 use an INT datatype instead of VARCHAR Quote Link to comment https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/#findComment-767386 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 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 > Quote Link to comment https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/#findComment-767388 Share on other sites More sharing options...
allworknoplay Posted February 20, 2009 Share Posted February 20, 2009 what is your column structure like? try this? SELECT * FROM `war` ORDER BY `war`. `MAX(td)` DESC LIMIT 1 I'm unfamiliary with putting the tildes there, why do you do that? Quote Link to comment https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/#findComment-767389 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/#findComment-767393 Share on other sites More sharing options...
allworknoplay Posted February 20, 2009 Share Posted February 20, 2009 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!!!! Quote Link to comment https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/#findComment-767396 Share on other sites More sharing options...
drisate Posted February 20, 2009 Author Share Posted February 20, 2009 thx guys i switched it to int and now works like a charme :-) Quote Link to comment https://forums.phpfreaks.com/topic/146166-solved-order-by-problem/#findComment-767398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.