Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need a help for Database select * sorting

See Image

here is my table SQL Query

CREATE TABLE IF NOT EXISTS tea_suppliers
(
    Suppliers_ID VARCHAR(10) NOT NULL UNIQUE,
    Name         VARCHAR(45) NOT NULL,
    ID           VARCHAR(12) NOT NULL UNIQUE,
    Address      VARCHAR(45) NOT NULL,
    Mobile_No    VARCHAR(10) NULL DEFAULT NULL,
    PRIMARY KEY (Suppliers_ID)
);

I need to display S01,S02,…,S09,S010,S011 like pattern.
But select * from display pattern like S01,S010,S011,S02,…,S09 (see image)
Please tell there is any way to do that

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You may sort on only the numeric portion of the Suppliers_ID:

SELECT *
FROM tea_suppliers
ORDER BY CAST(SUBSTRING(Suppliers_ID, 2) AS UNSIGNED);

Note that a better table design would be to make Suppliers_ID a pure numeric column. Then you could simply order using this column without making a cast.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading