SQL Practice Logo

SQLPractice Online

WHERE Clause & Filtering: Next

Module: SQL Fundamentals

Pattern Matching — LIKE, ILIKE, REGEXP, full-text search

Aggregate Functions & GROUP BY — filters that come after WHERE

HAVING — filtering on aggregate results

JOIN Operations — combining WHERE predicates across multiple tables

Indexes & Query Optimization — the physical structures WHERE predicates interact with

Write a WHERE clause that finds employees hired between 2020 and 2023 with salary above $75,000 in the Engineering or Product department — make it sargable

Identify all customers with NULL email OR NULL phone. Fix a version that uses = NULL and rewrite it correctly

Given the query WHERE UPPER(name) = 'ALICE', rewrite it to be sargable without changing the result

Write a NOT EXISTS anti-join to find all products that have never been ordered

Design the optimal composite index for: WHERE region = 'NA' AND status = 'active' AND created_at >= '2024-01-01' — explain your column order choice

Debug the AND/OR precedence bug: WHERE department = 'Sales' OR department = 'Marketing' AND quota_met = 1 — what does it return vs what was intended?

Why can't you use a SELECT alias in WHERE?

What does WHERE col = NULL return and why?

What is a sargable predicate? How do you identify and fix a non-sargable one?

Explain the left-prefix rule for composite indexes

When is NOT EXISTS safer than NOT IN?

What is three-valued logic and how does it affect AND and OR with NULLs?

Use The Index, Luke (use-the-index-luke.com) — comprehensive index and WHERE interaction guide

PostgreSQL documentation: Row Security Policies and WHERE interaction

MySQL 8.0 Reference: Index Condition Pushdown Optimization

The Art of SQL by Stephane Faroult — Chapter on filtering strategies

Itzik Ben-Gan's T-SQL Fundamentals — WHERE and logical query processing