Comparison Predicate
Compares the values of two expressions or the value of an expression and a single value returned by a subquery.
Syntax
<expression> {= | <> | > | < | >= | <=} {<expression> | <subquery>}
Notes: Comparison of strings in Access or a default installation of SQL Server is case-insensitive. The data type of the first expression must be compatible with the data type of the second expression or with the value returned by the subquery. If the subquery returns no rows or more than one row, an error is returned except when the select list of the subquery is COUNT(*), in which case the return of multiple rows yields one value. If the first expression, the second expression, or the subquery evaluates to Null, the result of the comparison is undefined.
Examples
To determine whether the sales date was in 2011, enter the following:
ear(DateSold) = 2011
To determine whether the invoice ID is not equal to 50, enter the following:
InvoiceID <> 50
To determine whether a product was sold in the first half of the year, enter the following:
Month(DateSold) < 7
To determine whether the date sold in the current row is less than the earliest order for ProductID 1, enter the following:
DateSold < (SELECT MIN(DateSold) FROM tblContactProducts WHERE ProductID = 1)
See also Expression, SELECT Statement, Subquery, and WHERE Clause in this tutorial.
In this tutorial:
- Understanding SQL
- SQL SELECT Queries
- BETWEEN Predicate
- Comparison Predicate
- EXISTS Predicate
- Expression
- FROM Clause
- GROUP BY Clause
- HAVING Clause
- IN Clause
- IN Predicate
- LIKE Predicate
- NULL Predicate
- PARAMETERS Declaration
- Quantified Predicate
- Search Condition
- SELECT Statement
- Subquery
- TRANSFORM Statement
- UNION Query Operator
- WHERE Clause
- SQL Action Queries
- INSERT Statement (Append Query)
- SELECT . . . INTO Statement (Make-Table Query)
- UPDATE Statement