SQL is not a procedural language, but it is a declarative language. Let’s take the example, basically, you tell the DBMS what you want, but you don't tell the DBMS how to get those results. It's up to the DBMS to understand this. A DBMS can apply multiple query strategies to get the correct result. However, these execution plans have different costs. It is the query optimizer's job to compare these strategies and choose the one with the lowest expected cost. Cost in this context is a weighted combination of input/output and processing costs. Input/output cost is the cost of accessing index and data pages from disk.  There are many ways to improve query performance. Here are a few best practices:   Avoid multiple joins in one query.  Use joins in place of subqueries.  Use stored procedures for commonly used data and more complex queries.  Use a WHERE expression to limit result size as much as possible.