The WHERE Clause
The previous section introduced one of the most important SQL
concepts, the WHERE
clause. In SQL, a WHERE
clause enables you to pick out specific rows in a table by specifying
a value that must be matched by the column in question. For example:
UPDATE bands SET lead_singer = 'Ian Anderson' WHERE band_name = 'Jethro Tull'
This UPDATE specifies that you should change only
the lead_singer column for the row where
band_name is identical to
Jethro
Tull. If the
band_name column is not a unique index, that
WHERE clause may match multiple rows. Many SQL
commands employ WHERE clauses to help pick out the
rows on which you wish to operate. Because the columns in the
WHERE clause are columns on which you search, you
should generally have indexes created around whatever combinations
you commonly use. We discuss the kinds of comparisons you can perform
in the WHERE clause later in the chapter.
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.
Read now
Unlock full access