This is a way to broad question to give a detailed answer. However, there is one general rule that holds true in development:
Don't reinvent the wheel
That is, unless you have a good reason. In the case of sorting, the developers of the database engine spend a lot more time writing an efficient sorting algorithm than you will be able to. So unless you need to sort by something like a field that is encrypted and cannot be decrypted on the database server, I would always sort on the database side.
However, if you have changing sorting requirements, like a display were the user selects which column to sort by, you are better of getting the data once and then sorting it in memory. The alternative of transferring the data again and again every time the sort order changes might be just too chatty on the network. Also a fully flexible query tends to be hard to optimize by the rdbms.
But then, if you are returning only the top few rows, sorting on the database site becomes a lot faster again, as the amount of data going over the network is greatly reduced.
That really brings us to the second general rule in database development:
It hope this was at least a little helpful. For a more detailed answer please give us more detail on your actual problem.