You can't trust that the database will do any particular ordering by itself.
I don't follow how you want to order, but the query below will order by category, and the rows within the same category gets ordered by id.
select something from table order by categoryid, id