Matching a Value with Subqueries

Subqueries can be used in the WHERE clause as the left side of an expression following one of the comparison operators shown in Table 6.1. A subquery that is used with a comparison operator must return a single value rather than a list of values. If such a subquery returns more than one value, the server will display an error message.

Table 6.1. Comparison Operators Used with Subqueries
Operator Description
= Equality
<> Not equal
> Greater than
>= Greater than or equal
< Less than
!> Not greater than
!< Not less than
<= Less than or equal

You would use a subquery with a comparison operator to select a value from either another table or the same table. You will realize rather quickly that subqueries will make your ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second 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.