SQL · Question 5 · Easy
SQL question 5
Table Employee:
id | name | dept | salary
1 | Asha | HR | 30000
2 | Ravi | IT | 50000
3 | Neha | IT | 60000
4 | Karan | Sales | NULL
5 | Priya | HR | 45000
6 | Vikram | IT | 50000
What is the output of the query?
SELECT COUNT(DISTINCT salary) FROM Employee;
- 6
- 5
- 4
- 3
Answer and explanation
Answer: C. 4
Explanation: COUNT(DISTINCT salary) ignores NULL and counts each value once. The distinct non-NULL salaries are 30000, 50000, 60000 and 45000, so the result is 4.
Previous: Which constraint ensures that all non-NULL values in a column are distinct… · Next: Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
Practise sql
Try a fresh set of sql questions with an explanation after every answer, free and without signing up: SQL practice. Or sit a full placement mock test.
More sql questions
- Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
- Which SQL command removes all rows from a table but keeps the table structure…
- Which constraint ensures that all non-NULL values in a column are distinct…
- Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
- Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
- Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
- Using a table Employee(id, name, dept, salary), which of the following queries…
- Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
- Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
- Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…
More technical & programming practice
Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code · C Programming · Java
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge