liveBook · Manning

Where clause

As explained in Grokking Relational Database Design

A WHERE clause is an SQL clause that restricts query results to rows satisfying a predicate.

A WHERE clause filters query results by keeping only rows that satisfy a condition. It works with SELECT and FROM: SELECT chooses columns, FROM chooses the table, and WHERE narrows the rows. section 1.5 section 1.7

Build a filter by following these practical rules:

  • Compare numeric values directly, such as price < 30. section 1.7
  • Compare text values with an equality sign and single quotes, such as manufacturer = 'Mad Inventors Inc.'. section 1.7
  • Join conditions with AND when every condition must match, or OR when either condition can match. section 1.7
  • Finish the query with a semicolon. section 1.5

Filter the product table

To retrieve product names and descriptions for products costing less than 30, write: SELECT name, description FROM product WHERE price < 30; To require both a price and manufacturer match, select every column and combine the conditions: SELECT * FROM product WHERE price < 30 AND manufacturer = 'Mad Inventors Inc.'; section 1.7

SELECT *
FROM product
WHERE price < 30 AND
manufacturer = 'Mad Inventors Inc.';

Inspect a complete WHERE clause that combines a numeric price condition with a manufacturer condition. section 1.7

How Grokking Relational Database Design covers it

How deep it goes
Explains numeric, string, and combined conditions with AND and OR, but does not descend into advanced filtering behavior.
Examples
Uses product names, prices, descriptions, and manufacturers in numeric, string, and combined filtering queries.
What it assumes
Introduces SELECT, FROM, and WHERE together as the basic structure of a first SQL query.
What you can do after
Apply it via SQL to retrieve only rows matching numeric, string, or combined conditions.
How it connects
Connects WHERE with SELECT, FROM, data types, comparison operators, logical operators, and GROUP BY.

Also explained in

Compare how 7 books explain where clause →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.