How to Order MySQL VARCHAR Results

后端 未结 3 426
傲寒
傲寒 2021-01-13 00:54

In a SELECT statement, I have a varchar column with ORDER BY DESC on it. Examples of data in this column:

1234
987
12-a
13-bh

MySQL would r

3条回答
  •  情深已故
    2021-01-13 01:14

    The easiest thing to do is this

    SELECT *
    FROM TBL
    ORDER BY VARCHAR_COLUMN * 1;
    

    To see what is happening, just add the column I used for ordering

    SELECT *, VARCHAR_COLUMN * 1
    FROM TBL
    ORDER BY VARCHAR_COLUMN * 1;
    

提交回复
热议问题