0

I need to fetch MySQL table value using one order using MySQL and PHP. I am providing my table below.

db_cat:

id     cat_name   cat_id     order_no

1       aaa        10          1

2       ggg        10          30

3        fff       10           11


4      sss         10           12

5      ddd         10            5

Here I am trying to fetch data as per order_no column value by using the query :

select * from db_cat where cat_id='10' order by order_no asc

but it is giving me the wrong order data like(11,12,30,1,5) where I should get the data like this order(1,5,11,12,30).

my order_no datatype is varchar.

1
  • 6
    Change order_no datatype to int Commented Apr 23, 2016 at 10:44

1 Answer 1

4

You can use a cast in order by

select * from db_cat where cat_id='10' order by cast(order_no as int) asc
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.