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 9205339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:55:43+00:00 2026-06-17T23:55:43+00:00

Hello i am trying to order by in mysql by sorting Special characters Letters

  • 0

Hello i am trying to order by in mysql by sorting

  • Special characters
  • Letters
  • then Numbers

it seems like mysql sorts by

  • Special Characters
  • Numbers
  • then Letters

See below

select distinct uag_linecode from part order by uag_linecode;

| A-1          |
| A/C          |
| A1S          |  out of place
| ABP          |
| ABS          |
| ACI          |
| ADM          |
| ADR          |
| BAS          |

This is what i want:

A-1 
A/C
ABR
ABS
ACI
ADM
ADR 
A1S correct spot
BAS

If anyone can help me out i would be eternally grateful.

All the line codes are always 3 characters long.

  • 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-06-17T23:55:44+00:00Added an answer on June 17, 2026 at 11:55 pm

    Something like this would work if it were always the 2nd character — you might be able to add to the case clause to check for 1st and 3rd characters…

    select distinct uag_linecode,
    substring(uag_linecode, 2, 1)
    from part
    order by 
      case 
        when substring(uag_linecode, 2, 1) REGEXP ('^[0-9]') THEN 1 ELSE 0 END , uag_linecode
    

    Here is the SQL Fiddle.

    –EDIT
    This appears to work for 1st and 3rd characters as well:

    select distinct uag_linecode,
       substring(uag_linecode, 1, 1),
       substring(uag_linecode, 2, 1),
       substring(uag_linecode, 3, 1)
    from part
    order by 
       case when substring(uag_linecode, 1, 1) REGEXP ('^[0-9]') THEN 1 ELSE 0 END,
       substring(uag_linecode, 1, 1),
       case when substring(uag_linecode, 2, 1) REGEXP ('^[0-9]') THEN 1 ELSE 0 END,
       substring(uag_linecode, 2, 1),
       case when substring(uag_linecode, 3, 1) REGEXP ('^[0-9]') THEN 1 ELSE 0 END ,    
       substring(uag_linecode, 3, 1)
    

    And more Fiddle.

    Also as @Orbling correctly says, you’ll get a better performance (especially if you have lots of records) to remove the REDEXP and use >= ‘0’ AND <= ‘9’.

    Good luck.

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

Sidebar

Related Questions

Hello I´m trying to automate AZURE VM management like Amazon EC2. Is there any
Hello im trying to echo only the 50 letters, but something in my code
http://img804.imageshack.us/img804/4258/uisketch.png Hello, I am trying to a make a UI, like in the sketch
Hello everyone: I am trying to get a data pull from MySQL within a
Hello all, I have a quick problem with mysql query. I'm trying to do
Hello there Iam trying to use the http://paste.kde.org api in order to make it
Hello I am trying to display work orders from my mysql database to show
Hello at the moment i'm trying to use jQuery in order to get ids
Hallo everyone i'm trying to use the initbinder annotations in order to match the
hello i am trying a sqlite database tutorial to build, but its not working

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.