Q.Compare the output produced by the query in example 8.6 and the following query and differentiate between the OR and AND operators.
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 →Example 8.6 uses AND, so a row must satisfy both conditions → only 6 employees qualify. The given query uses OR, so a row needs either condition — and since every employee earns more than 5000, all 10 rows come back.
AND = intersection (both true); OR = union (at least one true).
The two queries side by side
Example 8.6 (AND):
SELECT Ename, DeptId
FROM EMPLOYEE
WHERE Salary>=20000 AND Salary<=50000;
| Ename | DeptId |
|---|---|
| Shabbir | D01 |
| Joseph | D03 |
| Sanya | D02 |
| Nachaobi | D05 |
| Daribha | D04 |
| Tanya | D05 |
6 rows — with AND, a row is selected only when both conditions are true at the same time (salary at least 20000 and at most 50000). Kritika (60000) fails the second condition; Aaliya (10000), Vergese (15000) and Gurpreet (19000) fail the first — so all four are excluded.
The given query (OR):
SELECT *
FROM EMPLOYEE
WHERE Salary > 5000 OR
DeptId= 20;
Trace the first condition against Table 8.8: the lowest salary is Aaliya's 10000, so Salary > 5000 is already TRUE for every employee. With OR, one true condition is enough — MySQL never needs the second condition to admit the row. So the result is the whole table:
| 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 |
| 108 | Nachaobi | 29000 | NULL | D05 |
| 109 | Daribha | 42000 | NULL | D04 |
| 110 | Tanya | 50000 | 467 | D05 |
10 rows. …
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.