Consider the relation 'EMPLOYEE' : [EmpNo, Ename, Salary,Bonus, DeptId]
Which among the following SQL query will display the unique department number for all the employees from the given 'EMPLOYEE' relation?
Consider the relation 'EMPLOYEE' : [EmpNo, Ename, Salary,Bonus, DeptId]
Which among the following SQL query will display the unique department number for all the employees from the given 'EMPLOYEE' relation?
Solution
The DISTINCT keyword removes duplicate rows from the result, so select DISTINCT DeptId from EMPLOYEE; lists each department number only once.
Option 1: ALL is the default and keeps duplicates, so a DeptId repeats once for every employee in that department.
Option 2: UNIQUE is not a standard SQL keyword in a SELECT list. It is used for constraints, and only a few databases such as Oracle accept it as a synonym for DISTINCT.
Option 3: DIFFERENT is not an SQL keyword.
Related questions:
2025: 21 May Shift 1
2026: 18 May Shift 2
2026: 24 May Shift 1
2026: 23 May Shift 1