I have small question. Is query faster than while select statement? Or is it same? What is better to use? I know that query is better to use when users make some filter.
Query is much faster compare to While select.The difference is-
1)Query hits the DB once but while select hits the DB every time when the condition satisfies, in order to fetch the data from the database.
2)While select is recommended only when the no. of records to be fetched from DB is known in advance.
Thank you for the explanation
Taken from Best Practices Whitepaper:
“Use a query in place of a select statement when the structure of the “select” (query) is not known until run time, or when the user should be able to specify the ranges. In other situations, use a select statement. Select statements are often easier to read, and they are much more compile-time stable.”
In this text, selects statements imply also “while selects”.