Most of the times, when it comes to sort some data, we have two options:
- Sort on the SQL server — use ORDER BY clause
- Sort on client one we get the data from the database
When would you use one over the other and why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Always sort where possible in the SQL server.
The SQL abstracts away the steps of querying the database, sorting, etc. Use as much abstraction as you can – why would you select a bunch of rows, and then write a sorting algorithm when you can do it in the SQL with
ORDER BY.See also Bill Karwin’s answer.