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';
Count
510

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';
Count
1,257

The WHERE clause supports these operators.

TypeOperator NameSupported Types
Comparison Operators!=, =Numeric, String, Boolean
 <, <=, >, >=Numeric, String
 IN, NOT INNumeric, String
Null OperatorsIS NULL, IS NOT NULLNumeric
Logical OperatorsAND, OR, NOTBoolean

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.