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

  • Home
  • SEARCH
  • 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 6979135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:50:49+00:00 2026-05-27T17:50:49+00:00

I want to sort the following data items in the order they are presented

  • 0

I want to sort the following data items in the order they are presented below (numbers 1-12):

1
2
3
4
5
6
7
8
9
10
11
12

However, my query – using order by xxxxx asc sorts by the first digit above all else:

1
10
11
12
2
3
4
5
6
7
8
9

Any tricks to make it sort more properly?

Further, in the interest of full disclosure, this could be a mix of letters and numbers (although right now it is not), e.g.:

A1
534G
G46A
100B
100A
100JE

etc….

Thanks!

update: people asking for query

select * from table order by name asc
  • 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-27T17:50:50+00:00Added an answer on May 27, 2026 at 5:50 pm

    People use different tricks to do this. I Googled and find out some results each follow different tricks. Have a look at them:

    • Alpha Numeric Sorting in MySQL
    • Natural Sorting in MySQL
    • Sorting of numeric values mixed with alphanumeric values
    • mySQL natural sort
    • Natural Sort in MySQL

    Edit:

    I have just added the code of each link for future visitors.

    Alpha Numeric Sorting in MySQL

    Given input

    1A 1a 10A 9B 21C 1C 1D

    Expected output

    1A 1C 1D 1a 9B 10A 21C

    Query

    Bin Way
    ===================================
    SELECT 
    tbl_column, 
    BIN(tbl_column) AS binray_not_needed_column
    FROM db_table
    ORDER BY binray_not_needed_column ASC , tbl_column ASC
    
    -----------------------
    
    Cast Way
    ===================================
    SELECT 
    tbl_column, 
    CAST(tbl_column as SIGNED) AS casted_column
    FROM db_table
    ORDER BY casted_column ASC , tbl_column ASC
    

    Natural Sorting in MySQL

    Given input

    Table: sorting_test
     -------------------------- -------------
    | alphanumeric VARCHAR(75) | integer INT |
     -------------------------- -------------
    | test1                    | 1           |
    | test12                   | 2           |
    | test13                   | 3           |
    | test2                    | 4           |
    | test3                    | 5           |
     -------------------------- -------------
    

    Expected Output

     -------------------------- -------------
    | alphanumeric VARCHAR(75) | integer INT |
     -------------------------- -------------
    | test1                    | 1           |
    | test2                    | 4           |
    | test3                    | 5           |
    | test12                   | 2           |
    | test13                   | 3           |
     -------------------------- -------------
    

    Query

    SELECT alphanumeric, integer
           FROM sorting_test
           ORDER BY LENGTH(alphanumeric), alphanumeric  
    

    Sorting of numeric values mixed with alphanumeric values

    Given input

    2a, 12, 5b, 5a, 10, 11, 1, 4b
    

    Expected Output

    1, 2a, 4b, 5a, 5b, 10, 11, 12
    

    Query

    SELECT version
    FROM version_sorting
    ORDER BY CAST(version AS UNSIGNED), version;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following numpy matrix that I want to sort in ascending order
I want to be able to achieve the following using guice/gin: Get all sort
i have the following select box and want to sort it by display:none inlne
I want to sort the items that have been previously selected with checkboxes. If
I want to sort items in ListBox in aspx.net. I'm binding Datasource to my
I want to sort list items by their priority, which the user types in,
I want to sort ListView items by the content of second column (which can
I have an XML file whose contents I want to sort by document order
I'm trying to plot heatmap in ggplot2 using csv data following casbon's solution in
I saw the following function in a posting which allows one to order data

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.