Skip to content
Activities · Activity 9.8

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;]

Puducherry TnboardTextbookSubjective· 3mImportance★★★★★est
17% · 16/95 Questions
🔒 Locked · start free trial →

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

EnameDeptId
ShabbirD01
JosephD03
SanyaD02
NachaobiD05
DaribhaD04
TanyaD05

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:

EmpNoEnameSalaryBonusDeptId
101Aaliya10000234D02
102Kritika60000123D01
103Shabbir45000566D01
104Gurpreet19000565D04
105Joseph34000875D03
106Sanya48000695D02
107Vergese15000NULLD01

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.