WHERE Clause
By default, a SQL query retrieves every row in your dataset. Use the optional WHERE clause to restrict your query results to a conditional expression.
The conditional expression in the WHERE clause takes the following syntax.
1fieldExpression [logicalOperator fieldExpression2][...]
1SELECT COUNT(*) as Count
2FROM "Superstore"
3WHERE City = 'San Francisco';
You can add multiple field expressions to conditional expressions with logical operators.
1SELECT COUNT(*) as Count FROM "Superstore"
2WHERE City = 'Los Angeles' OR City = 'San Francisco';
The WHERE clause supports these operators.
| Type | Operator Name | Supported Types |
|---|
| Comparison Operators | !=, = | Numeric, String, Boolean |
| | <, <=, >, >= | Numeric, String |
| | IN, NOT IN | Numeric, String |
| Null Operators | IS NULL, IS NOT NULL | Numeric |
| Logical Operators | AND, OR, NOT | Boolean |
The left operand of a comparison operator must be a valid field. The right operand cannot be a field. Arithmetic operators (e.g. +, -, /, *, %) between supported types can be used on the right hand side.
WHERE is limited to comparisons within a single column.
In a non-nested query (a non-subquery), you can’t pass fields to a math or string function in a WHERE clause. You can pass a constant. To pass fields to a math or string function in a subquery, include it in the outer query’s WHERE clause. If you use it in the innermost query, SQL throws an error.