SQL Operators Practice Sheet
1. IN Operator
Use IN to match a value from a list.
Example:
SELECT name FROM employees WHERE department IN ('HR', 'IT');
Task:
Write a query to find employees from 'Sales' or 'Finance' departments.
2. BETWEEN Operator
BETWEEN checks if a value lies in a range (inclusive).
Example:
SELECT name FROM employees WHERE salary BETWEEN 40000 AND 60000;
Task:
Write a query to fetch employees hired between '2022-01-01' and '2023-01-01'.
3. IS and IS NOT Operators
Use IS NULL or IS NOT NULL to check for null values.
Example:
SELECT name FROM employees WHERE manager_id IS NULL;
Task:
Find employees who have a manager assigned.
4. LIKE Operator
LIKE helps with pattern matching using % and _.
Example:
SELECT name FROM students WHERE name LIKE 'A%';
Task:
Find all student names that end with 'a'.
5. UNION vs UNION ALL
UNION combines results and removes duplicates.
UNION ALL includes duplicates.
Task:
Write a query that lists all cities from two tables: domestic_customers and international_customers.
6. String Concatenation
Use || in Oracle/PostgreSQL, CONCAT() in MySQL, + in SQL Server.
SQL Operators Practice Sheet
Example (MySQL):
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees;
Task:
Display each employee like: 'Employee 101: Alice Rao'.