Understanding the SQL WHERE clause What does the WHERE clause restrict when you run a SELECT statement against a table or view?

Difficulty: Easy

Correct Answer: It limits which rows are returned.

Explanation:


Introduction / Context:
SELECT statements are composed of clauses with distinct responsibilities. Understanding what each clause does improves correctness and performance. Confusing the job of WHERE with SELECT or ORDER BY is a common beginner error.



Given Data / Assumptions:

  • We are discussing a standard SELECT ... FROM ... WHERE ... statement.
  • Columns vs rows are different concerns.
  • The DBMS evaluates clauses in a logical processing order (FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY).


Concept / Approach:

WHERE filters rows before projection. The SELECT list chooses which columns (and expressions) to return, while WHERE removes rows that do not satisfy the predicate. ORDER BY controls the result ordering and does not change which rows qualify.



Step-by-Step Solution:

Write a predicate, e.g., WHERE amount >= 1000.The DBMS evaluates rows and keeps only those meeting the condition.The SELECT list then projects specified columns.ORDER BY can sort the final qualifying rows.


Verification / Alternative check:

Logical query processing order shows WHERE acting before SELECT; thus, WHERE affects row qualification, not column selection.



Why Other Options Are Wrong:

  • A: Column limitation is done by SELECT, not WHERE.
  • C: Both is incorrect; WHERE does not choose columns.
  • D/E: WHERE absolutely affects which rows are returned.


Common Pitfalls:

  • Trying to reference column aliases from SELECT in WHERE (not allowed in many DBMSs because WHERE runs earlier).
  • Using WHERE to filter aggregated results instead of HAVING after GROUP BY.


Final Answer:

It limits which rows are returned.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion