0

I don't know is it possible or not I have subject code stings like this

Math 451
Math 451a
Math 452
Math 452a
Math 452b

I want query that would sort these string like this

Math 451
Math 452
Math 451a
Math 452a
Math 452b

I tried

CAST(SUBSTR(subjects.code,INSTR(subjects.code, " ") + 1) AS UNSIGNED)

but not working as expected thank you for your any help and suggestions

1 Answer 1

1

You could first sort by length of string and then by string itself:

SELECT code
FROM subjects
ORDER BY LENGTH(code), code;

Rextester Demo

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

Comments

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.