0
0
SQLquery~3 mins

Why WHERE with OR operator in SQL? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could find everything you want with just one simple question?

The Scenario

Imagine you have a big list of friends and you want to find those who like either pizza or ice cream. Without a smart way, you would have to look through the list again and again, checking each friend one by one for each favorite food.

The Problem

Manually checking each condition separately is slow and tiring. You might miss some friends who like one but not the other. It's easy to make mistakes and hard to keep track of all the checks.

The Solution

The WHERE with OR operator lets you ask for multiple conditions at once. It quickly finds all friends who like pizza or ice cream in one simple step, saving time and avoiding errors.

Before vs After
Before
SELECT * FROM friends WHERE likes_pizza = true;
SELECT * FROM friends WHERE likes_ice_cream = true;
After
SELECT * FROM friends WHERE likes_pizza = true OR likes_ice_cream = true;
What It Enables

This lets you easily find records that meet any of several conditions, making your searches flexible and powerful.

Real Life Example

In a store database, you can find customers who bought either shoes or hats with one query, instead of running separate searches for each product.

Key Takeaways

Manually checking multiple conditions is slow and error-prone.

WHERE with OR lets you combine conditions simply and clearly.

This makes searching for data that meets any condition fast and easy.