6. Filtering Rows with WHERE

6. Filtering Rows with WHERE

Idea: WHERE restricts rows returned. Only rows matching the condition are included.

Shape

SELECT * FROM TableName WHERE Column1 = 'Value';

Multiple Conditions

WHERE Price > 100 AND InStock = 1

Placeholders for Examples

Coming soon: filtering products by price and stock status.

Advanced Deep Dive ADVANCED

Predicate Pushdown: SQL Server tries to apply WHERE as early as possible for efficiency, but computed columns or functions can block this.

Parameterization: Use parameters in WHERE for plan reuse and security (avoid SQL injection).

NULL Handling: WHERE Column IS NULL is required for nulls; = NULL never matches.

Search Arguments (SARGs): Write WHERE clauses so indexes can be used; avoid wrapping columns in functions.

Row Security: SQL Server supports row-level security policies for dynamic WHERE filtering by user.

next