2

I want to sort last three numbers in following Pattern.

Pattern: 1AB23CD456

I have same pattern strings stored in mysql database.

Output I get:

1ab33cd401

1ab22cd201

1ab11cd101

1ab01cd301

Output I want:

1ab01cd101

1ab11cd201

1ab22cd301

1ab33cd401

And Before sorting last 3 numbers , I would like to sort numbers between ab and cd

I am using PHP server side scripting language, if required

1 Answer 1

2

If you want to sort the results with last three numbers you can use mysql's RIGHT() function

SELECT * FROM Table1 ORDER BY RIGHT(numbers,3)

Fiddle Demo

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks It worked, Do you know what if i want to sort numbers between ab and cd before sorting last 3 numbers.
@hsaka . . . You should ask another question. Your original question has been answered.
@hsaka Gordon is right you should ask another question for this but i am not sure for the occurrence of ab and cd's position ,if its same then you can do so fiddle demo
@MKhalidJunaid Thanks for your help, But ab and cd can be any character combination.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.