✅ SQL AND Operator – Combine Conditions in WHERE Like a Pro

Want to filter your SQL data using multiple conditions?
The SQL AND operator helps you return rows that satisfy all specified conditions—making your queries more precise and effective.


📌 What is SQL AND?

The AND operator is used within the WHERE clause to combine two or more conditions.
Only rows that meet all the conditions will be returned.

🧠 Think of it like a checklist:
All conditions must be ✅ true for the row to be included in the result.


🧾 SQL AND Syntax

SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2;
  • If both condition1 and condition2 are true → row is included.
  • If either condition is false → row is excluded.

✅ Simple Example: Filter Employees

SELECT first_name, last_name, department, salary
FROM employees
WHERE department = 'Sales'
AND salary > 50000;

🎯 This query returns employees who:

  • Work in the Sales department
  • Have a salary greater than 50,000

🔁 Example: Filter Products by Price & Availability

SELECT product_name, price, in_stock
FROM products
WHERE price < 1000
AND in_stock = 'yes';

🔍 Returns products priced under ₹1000 and currently in stock.


📊 Using AND with Dates

SELECT order_id, customer_id, order_date
FROM orders
WHERE order_date >= '2024-01-01'
AND order_date <= '2024-12-31';

✅ Filters orders placed in the year 2024.


🚫 Caution: Parentheses Help Clarity

When using AND with OR, use parentheses to ensure proper evaluation:

-- Without parentheses: may give unexpected results
SELECT * FROM orders
WHERE status = 'Pending'
OR status = 'Processing'
AND order_date > '2024-01-01';

-- Correct way:
SELECT * FROM orders
WHERE (status = 'Pending' OR status = 'Processing')
AND order_date > '2024-01-01';

💡 AND has higher precedence than OR.


🧪 Practice Challenge

Task: Find customers who are from ‘Delhi’ and have spent more than ₹10,000.

SELECT customer_name, city, total_spent
FROM customers
WHERE city = 'Delhi'
AND total_spent > 10000;

📝 Conclusion

The AND operator in SQL lets you:

✅ Combine multiple conditions
✅ Return only rows that meet all criteria
✅ Write dynamic, powerful WHERE filters for any real-world use case

Whether you’re querying customer records, product inventories, or transaction logs—AND is a must-have tool in your SQL arsenal.