Worked Examples · Example 9.6
Q.The following query selects the name and department number of all those employees who are earning salary between 20000 and 50000 (both values inclusive).
Puducherry TnboardTextbookSubjective· 2mImportance★★★★★
12% · 11/95 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →BETWEEN 20000 AND 50000 is inclusive on both ends. Run against the chapter's own EMPLOYEE table (Table 9.8), WHERE Salary BETWEEN 20000 AND 50000 (equivalently Salary >= 20000 AND Salary <= 50000) picks 6 of the 10 employees.
Concept: selection then projection
| Relational algebra | SQL clause | Purpose |
|---|---|---|
| Selection σ | WHERE | which rows survive |
| Projection π | column list after SELECT | which columns are shown |
SELECT Ename, DeptId
FROM EMPLOYEE
WHERE Salary >= 20000 AND Salary <= 50000;
Checking every row of Table 9.8
| Ename | Salary | In [20000, 50000]? |
|---|---|---|
| Aaliya | 10000 | no — below |
| Kritika | 60000 | no — above |
| Shabbir | 45000 | yes |
| Gurpreet | 19000 | no — below |
| Joseph | 34000 | yes |
| Sanya | 48000 | yes |
| Vergese | 15000 | no — below |
| Nachaobi | 29000 | yes |
| Daribha | 42000 | yes |
| Tanya | 50000 | yes — boundary included |
Output (6 rows):
+----------+--------+
| Ename | DeptId |
+----------+--------+
| Shabbir | D01 |
| Joseph | D03 |
| Sanya | D02 |
| Nachaobi | D05 |
| Daribha | D04 | …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.