0
0
SQLquery~5 mins

WHERE with AND operator in SQL

Choose your learning style9 modes available
Introduction
The WHERE clause with AND lets you find rows that match all conditions you want. It helps you get very specific results from your data.
When you want to find people who live in a city AND are older than 30.
When you want to get products that cost less than $20 AND are in stock.
When you want to see orders placed by a customer AND that are not yet shipped.
When you want to filter employees who work in a department AND have a certain job title.
Syntax
SQL
SELECT column1, column2
FROM table_name
WHERE condition1 AND condition2;
The AND operator means both conditions must be true for a row to be included.
You can use more than two conditions by adding more AND operators.
Examples
Find all employees who work in Sales and earn more than 50,000.
SQL
SELECT * FROM employees
WHERE department = 'Sales' AND salary > 50000;
Get names and ages of customers who live in New York and are at least 21 years old.
SQL
SELECT name, age FROM customers
WHERE city = 'New York' AND age >= 21;
List products that cost less than $20 and are currently in stock.
SQL
SELECT product_name FROM products
WHERE price < 20 AND stock > 0;
Sample Program
This creates a table of employees, adds some data, and then selects names and salaries of those who work in Sales and earn more than 50,000.
SQL
CREATE TABLE employees (
  id INT,
  name VARCHAR(50),
  department VARCHAR(50),
  salary INT
);

INSERT INTO employees VALUES
(1, 'Alice', 'Sales', 60000),
(2, 'Bob', 'Sales', 45000),
(3, 'Charlie', 'HR', 55000),
(4, 'Diana', 'Sales', 70000);

SELECT name, salary FROM employees
WHERE department = 'Sales' AND salary > 50000;
OutputSuccess
Important Notes
AND requires all conditions to be true; if any condition is false, the row is not included.
Use parentheses to group conditions if you mix AND with OR for clarity.
Check spelling and case sensitivity in string comparisons depending on your database.
Summary
The WHERE clause filters rows based on conditions.
AND combines conditions so all must be true.
Use it to get precise data matching multiple rules.