SQL AND Clause

The SQL AND clause is used to combine two or more conditions in a SQL query. The query will return rows where all specified conditions are true. It allows for more complex filtering.

If you have multiple conditions, all conditions must evaluate to true for a record to be included in the result set.

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' and the CustomerID is 101.

Code Example


-- Select orders where product is 'Laptop' and CustomerID is 101
SELECT * FROM Orders
WHERE Product = 'Laptop' AND CustomerID = 101;
            

Output

OrderID Product CustomerID Price
101 Laptop 101 750.00

Explanation

- The query retrieves orders where both conditions are true:
Product is 'Laptop' and CustomerID is 101.