Skip to main content
In this article, learn how to simplify SQL queries by using the IN operator in place of multiple OR conditions, ensuring cleaner syntax and easier maintenance.

Example: Using OR Conditions

Suppose you want to retrieve products where the price is either greater than 100 or less than 20. A common approach using OR conditions is as follows:
This query returns output similar to:

Example: Simplifying with the IN Operator

If you need to filter products based on specific IDs—such as 1, 2, and 3—the OR approach can be verbose:
Instead, using the IN operator streamlines the query considerably:
The output for this query may be as follows:
Using the IN operator not only reduces the repetition of SQL keywords but also improves readability, especially when filtering based on multiple values.

Recap of the IN Operator

Both methods—chaining multiple OR conditions and using the IN operator—yield the same result. However, the IN operator provides a more robust and clear solution to filter data across multiple values. Here is the concise version once again:
This approach is especially beneficial when dealing with larger sets of filtering criteria, making your queries easier to write and understand.

Watch Video