How to order 1,2,3 not 1, 10, 11, 12 in mySQL

前端 未结 6 1234
天涯浪人
天涯浪人 2020-12-29 02:22

The following code outputs in order of 1, 10, 11, 12 of id.

I want to make it 1,2,3,4...

Could anyone tell me what I should do please.

$Q = $         


        
6条回答
  •  温柔的废话
    2020-12-29 03:11

    You can do an explicit cast by doing:

    ORDER BY CAST(category_id AS UNSIGNED INTEGER)
    

    But you should reconsider you database layout as a field containing only numeric values should also be of an numeric type..

    Best wishes, Fabian

提交回复
热议问题