SQL OR Clause

The SQL OR clause is used to combine multiple conditions in a SQL query. Unlike the AND clause, where all conditions must be true, the OR clause allows for a row to be selected if any of the conditions are true.

This clause is useful when you need to retrieve records that match at least one of several conditions.

Table Structure

 
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
Product VARCHAR(50),
CustomerID INT,
Price DECIMAL(10, 2)
    );
    

Example

Let's retrieve all orders from the Orders table where the Product is 'Laptop' or the Price is greater than 1000.

Code Example


-- Select orders where product is 'Laptop' or price is greater than 1000
SELECT * FROM Orders
WHERE Product = 'Laptop' OR Price > 1000;
            

Output

OrderID Product CustomerID Price
101 Laptop 101 750.00
102 Phone 102 1200.00
103 Laptop 103 800.00

Explanation

- The query retrieves orders where Product is 'Laptop' or Price is greater than 1000.
- The OR operator returns records that match at least one of the conditions.