SQL SELECT
Q1. What is the SQL SELECT command?
SELECT is used to retrieve data from one or more tables. It supports filtering, grouping, sorting, and joining data. SELECT is the most commonly used SQL command.
Q2. How does the query optimizer work for SELECT statements?
The optimizer evaluates multiple execution plans based on statistics, indexes, and cost models. It selects the most efficient plan to minimize resource usage.
Q3. What are subqueries and when should they be used?
Subqueries are queries nested within another query. They are useful for complex logic but can impact performance if not optimized.
Q4. What is the difference between WHERE and HAVING?
WHERE filters rows before grouping, while HAVING filters groups after aggregation. Understanding this difference is critical for correct query results.
Q5. How do indexes improve SELECT performance?
Indexes reduce disk I/O by allowing fast lookups. However, too many indexes can slow down write operations.