đ Lab 2.1: ORDER BY, WHERE, DISTINCT in SQL
In this lab, we will learn how to sort and filter data using SQL's ORDER BY, WHERE, and DISTINCT clauses. We'll use a sample dataset with Bangladeshi employee names for realistic practice.
đ Sample Employees Table
ID | First Name | Last Name | Department | Salary |
---|---|---|---|---|
101 | Rakib | Hossain | IT | 70000 |
102 | Tamanna | Sultana | HR | 55000 |
103 | Imran | Ahmed | IT | 80000 |
104 | Naeem | Islam | HR | 50000 |
105 | Sharmin | Jahan | Marketing | 60000 |
đ§Ē SQL Practice Queries with Explanations
1. ORDER BY – Ascending Salary
SELECT * FROM employees
ORDER BY salary ASC;
This query lists all employees sorted by their salary from lowest to highest.
2. ORDER BY – Descending Salary
SELECT * FROM employees
ORDER BY salary DESC;
This will show the employees with the highest salary at the top.
3. WHERE – Filter by Department (IT)
SELECT * FROM employees
WHERE department = 'IT';
This query filters and shows only employees from the IT department.
4. WHERE – Salary Above 60,000
SELECT * FROM employees
WHERE salary > 60000;
This will return employees who earn more than 60,000.
5. DISTINCT – Unique Departments
SELECT DISTINCT department FROM employees;
Returns a list of unique department names without duplicates.
6. DISTINCT – Unique Salaries
SELECT DISTINCT salary FROM employees;
Returns a list of different salary values (no duplicates).
đ Summary
- ORDER BY – Sorts the result (ASC or DESC)
- WHERE – Filters rows based on conditions
- DISTINCT – Removes duplicate values
✅ Practice these to master basic data selection and sorting in SQL. Very useful for real-world data analysis and interview prep!
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ