General information about SQL AND - OR Usage

In SQL, the AND and OR operators are used to combine multiple conditions in queries. Here are some examples of the use of both operators:

AND Operator Examples:

  1. With Single Condition:
SELECT * FROM employees
WHERE department = 'IT' AND salary > 50000;

This query returns employees working in the "IT" department with a salary of more than 50,000.

  1. With Multiple Conditions:
SELECT * FROM products
WHERE category = 'Electronics' AND price < 1000 AND stock_quantity > 0;

This query returns the products in the electronics category with a price less than 1000, which are also in stock.

OR Operator Examples:

  1. With Single Condition:
SELECT * FROM customers
WHERE city = 'New York' OR city = 'Los Angeles';

This query retrieves customers living in New York or Los Angeles using the or condition.

  1. With Multiple Conditions:
SELECT * FROM orders
WHERE order_status = 'Shipped' OR (order_status = 'Processing' AND payment_status = 'Paid');

This query returns orders with order status "Shipped" or orders with order status "Processing" and payment status "Paid".

AND and OR Combination:

SELECT * FROM products
WHERE (category = 'Clothing' AND price < 50) OR (category = 'Electronics' AND stock_quantity > 0);