Which of the following SQL command is correct to select the name (Ename) and department number (DeptId) of all those employees from the relation 'EMPLOYEE' who are earning Salary between 20000 and 50000 (both values inclusive)?
Which of the following SQL command is correct to select the name (Ename) and department number (DeptId) of all those employees from the relation 'EMPLOYEE' who are earning Salary between 20000 and 50000 (both values inclusive)?
Solution
"Both values inclusive" means salaries of exactly 20000 and exactly 50000 must be included. So both bounds need the inclusive operators and , which is what Option 3 uses: Salary>=20000 AND Salary<=50000. This is the same as Salary BETWEEN 20000 AND 50000, since BETWEEN in SQL includes both end values.
Option 1: excludes 20000, because it uses for the lower bound.
Option 2: excludes both 20000 and 50000.
Option 4: the conditions are reversed. No salary can be and at the same time, so it returns no rows.
Related questions:
2026: 29 May Shift 2
2025: 27 May Shift 2