Selecting Rows: The WHERE Clause

The WHERE clause is the part of the SELECT statement that specifies the search conditions. These conditions determine exactly which rows are retrieved. The general format is this:

SELECT select_list
FROM table_list
WHERE search_conditions

When you run a SELECT statement with a WHERE clause, your system searches for the rows in the table that meet your conditions (also called qualifications).

SQL provides a variety of operators and keywords for expressing the search conditions, including these:

  • Comparison operators (=, <, >, and so on)

    select title
    from titles
    where advance * 2 > ytd_sales * price
    
  • Combinations or logical negations of conditions (AND, OR, NOT)

    select title
    from titles
    where advance < 5000 or

Get Practical SQL Handbook, The: Using SQL Variants, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.