Skip to Content
Learning SQL, 3rd Edition
book

Learning SQL, 3rd Edition

by Alan Beaulieu
March 2020
Beginner
380 pages
9h 44m
English
O'Reilly Media, Inc.
Book available
Content preview from Learning SQL, 3rd Edition

Chapter 4. Filtering

Sometimes you will want to work with every row in a table, such as:

  • Purging all data from a table used to stage new data warehouse feeds

  • Modifying all rows in a table after a new column has been added

  • Retrieving all rows from a message queue table

In cases like these, your SQL statements won’t need to have a where clause, since you don’t need to exclude any rows from consideration. Most of the time, however, you will want to narrow your focus to a subset of a table’s rows. Therefore, all the SQL data statements (except the insert statement) include an optional where clause containing one or more filter conditions used to restrict the number of rows acted on by the SQL statement. Additionally, the select statement includes a having clause in which filter conditions pertaining to grouped data may be included. This chapter explores the various types of filter conditions that you can employ in the where clauses of select, update, and delete statements; I demonstrate the use of filter conditions in the having clause of a select statement in Chapter 8.

Condition Evaluation

A where clause may contain one or more conditions, separated by the operators and and or. If multiple conditions are separated only by the and operator, then all the conditions must evaluate to true for the row to be included in the result set. Consider the following where clause:

WHERE first_name = 'STEVEN' AND create_date > '2006-01-01'

Given these two conditions, only rows ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning SQL

Learning SQL

Ben Forta
Practical SQL

Practical SQL

Anthony DeBarros
Head First SQL

Head First SQL

Lynn Beighley

Publisher Resources

ISBN: 9781492057604Errata Page