đ Lab 2.2: SQL Filtering — AND, OR, IN, BETWEEN, LIKE, IS NULL
In this lab, you will learn how to filter data in SQL using advanced condition operators: AND, OR, IN, BETWEEN, LIKE, and IS NULL. We will use a sample employee table with Bangladeshi names.
đ Sample Employees Table
ID | First Name | Last Name | Department | Salary | |
---|---|---|---|---|---|
201 | Rakib | Hasan | IT | 70000 | rakib@company.com |
202 | Tamanna | Sultana | HR | 55000 | tamanna@company.com |
203 | Imran | Ahmed | Sales | 72000 | |
204 | Sharmin | Jahan | Marketing | 60000 | sharmin@company.com |
205 | Naeem | Islam | IT | NULL | naeem@company.com |
đ§Ē SQL Practice Queries with Explanation
1. AND – Filter by Department and Salary
SELECT * FROM employees
WHERE department = 'IT' AND salary > 60000;
This shows employees who are in IT department and have salary above 60,000.
2. OR – Either Department is HR or Salary below 60,000
SELECT * FROM employees
WHERE department = 'HR' OR salary < 60000;
Returns anyone from HR or anyone earning less than 60,000.
3. IN – Match Any Value from a List
SELECT * FROM employees
WHERE department IN ('HR', 'Sales');
Shows employees who are either in HR or Sales departments.
4. BETWEEN – Salary Between 55000 and 70000
SELECT * FROM employees
WHERE salary BETWEEN 55000 AND 70000;
Returns employees whose salary is in the range 55,000–70,000 inclusive.
5. LIKE – Name Starting with 'Sh'
SELECT * FROM employees
WHERE first_name LIKE 'Sh%';
Finds all employees whose first name starts with "Sh", such as "Sharmin".
6. IS NULL – Email Field is Empty
SELECT * FROM employees
WHERE email IS NULL;
Returns records where the email is missing (NULL).
đ Summary
- AND – Both conditions must be true
- OR – Either condition can be true
- IN – Match against multiple values
- BETWEEN – Check if value is in a range
- LIKE – Pattern matching (use % for wildcard)
- IS NULL – Checks if a value is missing
✅ These SQL operators are essential for real-life data filtering. Practice them regularly to sharpen your SQL query skills.
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ