I am working in content management of an E-Book publication database. Text contents are stored in eb_contents (VARCHAR) TABLE and accessed by page_name (VARCHAR). My page_name value like below –
EBook-00GUKP1142-10.jpg EBook-00GUKP1142-11.jpg EBook-00GUKP1142-12.jpg EBook-00GUKP1142-7.jpg EBook-02GUKP1375-1.jpg EBook-02GUKP1375-4.jpg EBook-02GUKP1375-5.jpg EBook-02GUKP1375-52.jpg EBook-02GUKP1375-53.jpg EBook-02GUKP1375-56.jpg EBook-02GUKP1375-57.jpg EBook-02GUKP1375-6.jpg EBook-04GUKP2577-17.jpg EBook-04GUKP2577-26.jpg EBook-04GUKP2577-27.jpg EBook-04GUKP2577-28.jpg EBook-04GUKP2577-68.jpg EBook-04GUKP2577-69.jpg EBook-05GUKP1661-1.jpg
I have tried implementing different sorting methods like below. But unable to get the result as expected. Any help is most welcome.
SELECT * FROM `eb_contents` ORDER BY Cast(page_name as Unsigned), page_name;
2
Answers
For your input only
Try This
output
You need to convert to an numeric type to get the correct ordering.
Schema (MySQL v5.7)
Query #1
Query #2
View on DB Fiddle