SQL WHERE With Multiple Conditions: Syntax and Examples

To use multiple conditions in SQL, combine them in one WHERE clause with AND, OR, and parentheses. The important part is grouping the conditions so the query includes exactly the rows you intend. The examples below cover required conditions, alternative matches, same-column filters, NULL, conditional logic, and filtering grouped results.

How Multiple WHERE Conditions Work

A WHERE clause filters rows using a Boolean expression. A row is returned only when the complete expression evaluates to TRUE; rows producing FALSE or UNKNOWN are excluded.

Each SELECT query block has one WHERE clause. Adding another condition does not mean adding another WHERE keyword, you extend the existing expression.

Decide whether your conditions describe requirements for the same row or requirements across different rows. A single customer row can satisfy both a city condition and an age condition. Finding customers who have separate orders for different products requires checking those order rows together.

The examples use illustrative tables named customers, products, and employees. Replace those table and column names with your schema. Assume that age is stored in years and monetary columns store US dollars.

How to Write a WHERE Clause With Multiple Conditions

Choose the relationship between your conditions before writing the filter.

What the Row Must Satisfy Use Typical Purpose
Every requirement AND Match a location and an age requirement
At least one alternative OR Accept either of two eligibility rules
One of several complete rule groups Parentheses with AND and OR Apply different requirements to different categories
None of a grouped set of alternatives NOT (...) Exclude rows matching an unwanted group

Step 1: Define the Rule and Identify the Columns

  1. Write the rule in ordinary language, including words such as “both,” “either,” and “except.”
  2. Identify the table, the columns being filtered, and the columns you want returned.

For example, “customers who live in New York and are older than 30” contains two requirements for the same customer row.

Check the column types before writing comparisons. Use single quotes around text values, but write numeric values as numbers when comparing numeric columns. For example, a numeric age comparison should not depend on converting text into a number.

Step 2: Connect the Conditions With AND or OR

  1. Use AND to require both the city and age comparisons to be true for the same customer row.

The general pattern below uses placeholder conditions; replace them with your comparisons:

WHERE condition1 AND condition2 AND condition3;

For the customer rule, the complete query is:

SELECT customer_id, city, age
FROM customers
WHERE city = 'New York' AND age > 30;

A customer must pass both comparisons. Someone at the age boundary does not qualify because the operator is strictly greater than.

  1. Use OR to accept a customer who passes the city comparison, the age comparison, or both.

The corresponding pattern is:

WHERE condition1 OR condition2 OR condition3;

Changing the customer query to OR changes its meaning:

SELECT customer_id, city, age
FROM customers
WHERE city = 'New York' OR age > 30;

This accepts New York customers regardless of their age, plus customers elsewhere who pass the age test. A row satisfying both conditions still appears only once because of this filter; OR does not duplicate it.

Step 3: Group Mixed Conditions With Parentheses

  1. Within each alternative, join the required comparisons with AND; enclose each alternative in parentheses and connect the groups with OR.

Suppose products qualify under either a category-specific electronics rule or a separate books rule:

SELECT product_id, category, price
FROM products
WHERE (category = 'Electronics' AND price < 500)
   OR (category = 'Books' AND price < 20);

Each parenthesized group describes one acceptable kind of product. A row needs to satisfy either whole group, not individual pieces taken from different groups.

SQL generally gives NOT higher precedence than AND, and AND higher precedence than OR. In this example, the parentheses make the intended groups explicit even though the default precedence produces the same grouping.

  1. Connect a shared requirement with AND to a parenthesized group of alternatives so every matching row must satisfy it.

For example, if in_stock is an integer flag, this query requires stock availability for either category:

SELECT product_id, category, in_stock
FROM products
WHERE in_stock = 1
  AND (category = 'Electronics' OR category = 'Books');

Without those parentheses, the stock requirement would apply only to electronics, and every book would qualify.

Parentheses control logical grouping.

Step 4: Run the SELECT and Check the Returned Rows

  1. Run the SELECT in your database client with the filtered columns in the output. For the category-and-price query, include category and price so each returned product can be checked against the rule.

I use a database client to inspect returned IDs alongside the filter columns, because a row count can hide incorrect matches.

  1. Check both expected matches and expected exclusions, including products priced exactly at the cutoffs and products outside the accepted categories.

For the category-and-price query, these illustrative records make a useful check:

Product ID Category Price (USD) Should Match?
1 Electronics $499 Yes
2 Electronics $500 No
3 Books $19 Yes
4 Books $20 No
5 Clothing $10 No

Only product IDs 1 and 3 should be returned from this sample. Once the output matches the intended rule, the filter is ready to use in the surrounding query.

Same-Column Filters, Ranges, and NULL

Match Several Values With IN

When several acceptable values belong to the same column, IN is usually clearer than repeated equality comparisons joined by OR:

SELECT customer_id, city
FROM customers
WHERE city IN ('New York', 'Boston', 'Chicago');

The IN filter returns customers whose city is New York, Boston, or Chicago.

Do not join different equality values for one scalar column with AND when you mean “either.” A single city value cannot simultaneously equal two different city names.

You can still combine a set-membership test with another required condition:

SELECT customer_id, city, account_status
FROM customers
WHERE city IN ('New York', 'Boston', 'Chicago')
  AND account_status = 'active';

This returns active customers in any of the listed cities.

Filter Ranges With BETWEEN

Use BETWEEN for an inclusive range:

SELECT customer_id, age
FROM customers
WHERE age BETWEEN 18 AND 65;

Both endpoints are included. If either endpoint should be excluded, use explicit comparison operators instead.

Be more careful with timestamp columns. For a calendar period, an inclusive start and an exclusive start of the next period are often easier to get right than BETWEEN: an upper bound at midnight does not include the rest of that day. Bind the boundaries using date or timestamp values appropriate to your database and column type.

Exclude a Group With NOT

Use NOT around a grouped expression to reject the whole alternative:

SELECT employee_id, department, salary
FROM employees
WHERE NOT (department = 'HR' OR salary > 100000);

This keeps employees in known non-HR departments whose known salary is at most $100,000. It does not include rows where either of those columns is NULL.

The parentheses matter because NOT must apply to the complete group rather than just one comparison.

Handle NULL Explicitly

NULL represents missing or unknown information. Ordinary comparisons with NULL, including equality and inequality, produce UNKNOWN rather than a normal true-or-false result.

Use IS NULL or IS NOT NULL to test for missing values. For example, this rule includes non-HR employees and employees whose department is missing:

SELECT employee_id, department
FROM employees
WHERE department <> 'HR'
   OR department IS NULL;

Decide explicitly whether missing values belong in your result. “Not equal to HR” and “not equal to HR or missing” are different rules.

Also watch NOT IN: if its list or subquery results contain NULL, otherwise eligible rows can fail to pass. Keep missing values out of the exclusion set, and account separately for missing values in the column being filtered.

Conditional Filters With CASE

Use a CASE expression when a WHERE rule genuinely needs if-else-then logic, for example, when the value used in a comparison changes by department. Ordinary combinations of requirements do not need CASE.

Suppose the minimum eligible salary is $60,000 for Sales, $70,000 for Engineering, and $50,000 for other departments:

SELECT employee_id, department, salary
FROM employees
WHERE salary >= CASE
    WHEN department = 'Sales' THEN 60000
    WHEN department = 'Engineering' THEN 70000
    ELSE 50000
END;

The expression returns a threshold, which the outer comparison checks against each employee’s salary. Because neither department comparison is true for a missing department, that row uses the ELSE threshold.

A CASE expression returns the value from the first WHEN clause that is true, according to Oracle’s SQL documentation. Order overlapping conditions from highest priority to lowest priority.

If no WHEN matches and there is no ELSE, the expression returns NULL. In a comparison like this one, that produces UNKNOWN, so the row is excluded.

CASE produces a value; it is not a procedural command that runs arbitrary SQL statements. Before using it, check whether a straightforward combination of predicates would express the rule more clearly.

Use WHERE and HAVING Together

Use WHERE to filter individual rows and HAVING to filter groups after aggregation. They can appear in the same query, and each can contain multiple conditions.

For example, this query considers employees with positive salaries, then keeps departments meeting both group-level requirements:

SELECT
    department,
    COUNT(*) AS employee_count,
    AVG(salary) AS average_salary
FROM employees
WHERE salary > 0
GROUP BY department
HAVING COUNT(*) >= 5
   AND AVG(salary) > 60000;

The logical sequence is:

  1. WHERE removes rows that do not pass the salary filter.
  2. GROUP BY forms department groups from the remaining rows.
  3. HAVING keeps groups with at least five employees and an average salary above $60,000.

The count and average therefore describe the rows remaining after WHERE, not every employee originally in the table.

Do not put aggregate conditions such as a group’s employee count directly in the WHERE clause of the same query block. Use HAVING, or calculate the aggregate in a subquery and filter its result in an outer query.

Check Query Behavior and Performance

A longer WHERE clause is not automatically slower. Performance depends on the data distribution, available indexes, joins, and the execution plan, not simply the number of conditions.

Do Not Rely on Predicate Evaluation Order

Changing the order of ordinary AND conditions does not tell the database which one to execute first. The optimizer can rearrange predicates or choose a different access strategy.

Do not rely on a condition on the left to protect an unsafe expression on the right. For example, checking for a nonzero denominator with AND is not a dependable way to prevent division errors. Make the expression itself safe, such as by converting a zero denominator to NULL with NULLIF before division.

Inspect Index Use Before Rewriting the Query

Functions or CASE expressions around indexed columns can limit the optimizer’s ability to use an ordinary index efficiently. Where practical, compare the stored column directly with a suitable value or range. Expression-based indexes may help where your database supports them, but they are not interchangeable across database systems.

Use your database client’s execution-plan feature to inspect how the query accesses data. Choose indexes based on the actual workload rather than assuming that every filtered column needs its own index.

For Oracle AI Database versions that support SQL transpilation, the sql_transpiler parameter must be set to on to enable eligible PL/SQL function predicates to be transpiled into SQL expressions; it is off by default, according to Oracle’s SQL guidance. Check whether your installed Oracle AI Database version supports SQL transpilation and how its sql_transpiler parameter behaves. This setting is not needed for ordinary AND/OR filters.

Keep Application Values Separate From SQL Text

When the filter receives user input, use your database driver’s bound parameters instead of concatenating values into SQL. Parameter placeholder syntax varies by driver, so use its documented format.

If the application builds optional filters, append approved SQL fragments and bind their values separately. Do not accept arbitrary column names or operators as though they were ordinary value parameters.

Before deploying the query, test it with representative data and inspect its execution plan. Change indexes or rewrite predicates only after confirming both the intended results and the actual performance bottleneck.

Frequently Asked Questions

How Do I Use Two Conditions in SQL Server Management Studio?

Use one WHERE clause joined with AND when both conditions must match. SSMS is the query editor; the connected SQL Server engine interprets the statement.

SELECT employee_id, department, employment_status
FROM employees
WHERE department = 'Sales'
  AND employment_status = 'active';

Can One SQL Statement Contain Multiple WHERE Clauses?

Yes, if they belong to separate query blocks, such as an outer query and a subquery. You cannot write consecutive WHERE clauses for the same SELECT block.

SELECT c.customer_id
FROM customers AS c
WHERE c.account_status = 'active'
  AND EXISTS (
      SELECT 1
      FROM orders AS o
      WHERE o.customer_id = c.customer_id
        AND o.order_status = 'paid'
  );

This returns active customers with at least one paid order; each WHERE belongs to a different query block.

How Can I Require Two Values in the Same Column Across Different Rows?

Group the rows by the entity you care about, filter to the required values, and require both distinct values to be present. For a customer_tags table, this query finds customers with both the vip and newsletter tags:

SELECT customer_id
FROM customer_tags
WHERE tag IN ('vip', 'newsletter')
GROUP BY customer_id
HAVING COUNT(DISTINCT tag) = 2;

Using DISTINCT prevents duplicate copies of one tag from incorrectly satisfying the requirement.

Why would an SQL statement use multiple OR conditions?

Multiple OR conditions let a row qualify when it satisfies at least one of several acceptable alternatives. When you mix OR with AND, place parentheses around each complete alternative so the filter applies the rule groups you mean.