Q.Compare the output produced by the query in Example 9.6 and the output of the following query and differentiate between the OR and AND operators.
[Context: Example 9.6 query — SELECT Ename, DeptId FROM EMPLOYEE WHERE Salary>=20000 AND Salary<=50000; The following query — SELECT * FROM EMPLOYEE WHERE Salary > 5000 OR DeptId= 20;]
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 →AND requires all conditions to be true; OR requires at least one. Run both queries against the chapter's own EMPLOYEE table (Table 9.8): the AND query (Example 9.6) returns 6 of the 10 employees, while the OR query returns all 10 — because every employee in Table 9.8 already earns more than 5000, so Salary > 5000 alone is enough to admit every row.
The two queries
Example 9.6 (AND):
SELECT Ename, DeptId
FROM EMPLOYEE
WHERE Salary >= 20000 AND Salary <= 50000;
This activity's query (OR):
SELECT *
FROM EMPLOYEE
WHERE Salary > 5000 OR DeptId = 20;
Output of Example 9.6 (AND) — 6 rows
| Ename | DeptId |
|---|---|
| Shabbir | D01 |
| Joseph | D03 |
| Sanya | D02 |
| Nachaobi | D05 |
| Daribha | D04 |
| Tanya | D05 |
Only employees whose salary is between 20000 and 50000 inclusive survive — Aaliya (10000), Vergese (15000) and Gurpreet (19000) fall short, and Kritika (60000) is over.
Output of the OR query — all 10 rows
Every salary in Table 9.8 (10000 to 60000) is already above 5000, so Salary > 5000 alone is true for every row — OR DeptId = 20 never gets the chance to matter (and DeptId is a text column like 'D01', which can't sensibly equal the number 20 anyway). Because OR only needs one side to be true, all 10 employees are returned:
| EmpNo | Ename | Salary | Bonus | DeptId |
|---|---|---|---|---|
| 101 | Aaliya | 10000 | 234 | D02 |
| 102 | Kritika | 60000 | 123 | D01 |
| 103 | Shabbir | 45000 | 566 | D01 |
| 104 | Gurpreet | 19000 | 565 | D04 |
| 105 | Joseph | 34000 | 875 | D03 |
| 106 | Sanya | 48000 | 695 | D02 |
| 107 | Vergese | 15000 | NULL | D01 |
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.