Page 74 - SQL
P. 74
Chapter 22: Filter results using WHERE and
HAVING
Syntax
• SELECT column_name
FROM table_name
WHERE column_name operator value
• SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
Examples
The WHERE clause only returns rows that match its criteria
Steam has a games under $10 section of their store page. Somewhere deep in the heart of their
systems, there's probably a query that looks something like:
SELECT *
FROM Items
WHERE Price < 10
Use IN to return rows with a value contained in a list
This example uses the Car Table from the Example Databases.
SELECT *
FROM Cars
WHERE TotalCost IN (100, 200, 300)
This query will return Car #2 which costs 200 and Car #3 which costs 100. Note that this is
equivalent to using multiple clauses with OR, e.g.:
SELECT *
FROM Cars
WHERE TotalCost = 100 OR TotalCost = 200 OR TotalCost = 300
Use LIKE to find matching strings and substrings
See full documentation on LIKE operator.
This example uses the Employees Table from the Example Databases.
https://riptutorial.com/ 56

