Which method would be fastest / most efficient?
A) Read all data (822 rows) including those I do not need then filter / output those I do
B) 3 Round trips to the db using params filled via the last query to select only the data I need
Thanks.
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.
It depends, but it shouldn’t require three round trips.
It’s almost always faster to filter the desired results at the database level with a well-formed WHERE clause on your SQL statement (if it’s an ad-hoc query). Better still is to build a stored procedure with parameters you can pass from the front end. This is faster because the SQL does not need to be recompiled each time and more secure because it prevents ad-hoc SQL injection etc.
However, for a full answer, we’ll need more information on what you’re trying to achieve i.e. are you going for some sort of paging mechanism?