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

前端 未结 6 1287
天涯浪人
天涯浪人 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 02:56

    First, add an order by clause at the end:

    ORDER BY category_id
    

    If category_id is a string, then you must treat it like an integer. There are a few ways to do this. I usually add a zero. You can also cast it.

    ORDER BY category_id + 0
    

提交回复
热议问题