Hi all,

categories_id (PK,AI),categories_name(varchar(150)), categories_order(int), categories_image(varchar(100)), categories_status(int)

This is my table structure. My server side language is PHP. User has to insert values to this table where categories_order(int) is optional. If the user miss categories_order(int) then it will be filled with zero. On select query, all rows must to sorted with categories_order(int) in ASC ( as SELECT * FROM `categories` order by `categories_order` asc ) but when I execute the query, categories_order with zero's ( where users didn't fill the order field )comes on the top.

I want to sort the table such a way that rows with category_order will be show at top in ASC then it should show other rows ( where category_order is zero ) with category_name in ASC.

How can I achieve this ? Thank you for the interest

You can use a UNION. Sort ASC the ones > 0 and union them with the ones that are zero.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.