Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 902033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:39:11+00:00 2026-05-15T15:39:11+00:00

How do you order by number if your number can fall below and be

  • 0

How do you order by number if your number can fall below and be bigger than 0?

Example Mysql table:

|Name|Karma|
 __________
|Me  | -8  |
|Bill|  5  |
|Tom |  2  |
|Saly|  0  |
|San.| -3  |

Example select query

$sql="SELECT karma FROM table ORDER BY karma DESC";

The result I get is this (separated by comma): 5,2,0,-8,-3.
Shouldn’t it be 5,2,0,-3,-8?
I discovered somewhere in the internet that mysql orders by string. How to make it order by number?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:39:12+00:00Added an answer on May 15, 2026 at 3:39 pm

    Karma will be ordered as a string if you have made it a string, i.e. a varchar column.

    Convert the column to a INT, and it will order numerically.

    You also have the option of not changing the table, but casting the column into the right type while sorting:

    SELECT karma FROM table ORDER BY CAST(karma AS int) DESC
    

    but that is bad for performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I insert automatic number to field id in mysql? I have idmember
the order number of hidden field in grid view is 7. when i click
I have records in the database with the sort order number. Now I want
There are two strings. String str1=Order Number Order Time Trade Number; String str2=Order Tm;
i need to get number of order highlighted element (by javascript, jquery): <li>A</li> <li>B</li>
How can I add ELSE clause to the following code? ROW_NUMBER() OVER (ORDER BY
I have a number of check or money order payments that I received through
I want to update Paypal Order status and add tracking number using API. but
In order to have a well scrambled table (for a psychological experiment), I'd like
I want to do a MySQL Query which selects a given number of Rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.