In the SQL WHERE clause, various operators can be used to specify the condition for filtering data. Here are some commonly used operators in the WHERE clause:
Example: Retrieve all customers whose age is greater than 25.
SELECT * FROM customers
WHERE age > 25;
Example: Retrieve all customers whose age is between 20 and 30 and whose country is ‘USA’.
SELECT * FROM customers
WHERE age BETWEEN 20 AND 30 AND country = 'USA';
Example: Retrieve all customers whose last name starts with ‘S’.
SELECT * FROM customers
WHERE last_name LIKE 'S%';
Example: Retrieve all customers whose country is either ‘USA’, ‘Canada’, or ‘Mexico’.
SELECT * FROM customers
WHERE country IN ('USA', 'Canada', 'Mexico');
Example: Retrieve all orders whose order date is between January 1, 2022 and December 31, 2022.
SELECT * FROM orders
WHERE order_date BETWEEN '2022-01-01' AND '2022-12-31';
These are some commonly used operators in the SQL WHERE clause. By using these operators, you can filter data based on specific conditions and retrieve only the data that meets those conditions.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.