Question 1
EasyWhat does this query return?
SELECT dept, COUNT(*)
FROM employees
dept
() ;
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
DBMS
What does this query return?
SELECT dept, COUNT(*)
FROM employees
dept
() ;
All departments with their employee count
Departments that have more than 2 employees
Employees who belong to more than 2 departments
An error because HAVING needs WHERE
Answer: B
GROUP BY makes one group per department, and HAVING filters those groups after counting, keeping only departments with more than 2 employees. HAVING does not need a WHERE clause.
Which SQL clause filters rows before grouping?
GROUP BY
WHERE
HAVING
ORDER BY
Answer: B
WHERE filters individual rows; HAVING filters groups after GROUP BY.
Which clause sorts the result of a query?
GROUP BY
ARRANGE BY
ORDER BY
SORT BY
Answer: C
ORDER BY column [ASC | DESC] sorts the result; ascending is the default.
Which keyword removes duplicate rows from a query result?
SINGLE
DIFFERENT
UNIQUE
DISTINCT
Answer: D
SELECT DISTINCT dept FROM employee lists each department once.
Which aggregate function counts rows?
COUNT()
TOTAL()
SUM()
NUMBER()
Answer: A
COUNT(*) counts all rows; COUNT(column) counts non-null values in that column.
Which operator matches a pattern in SQL?
SIMILAR
MATCH
PATTERN
LIKE
Answer: D
name LIKE 'A%' matches names starting with A; % matches any sequence of characters and _ matches exactly one.
How do you check whether a column is NULL in SQL?
salary = NULL
salary IS NULL
salary EQUALS NULL
salary == NULL
Answer: B
Comparisons with NULL using = give UNKNOWN, never TRUE, so you must use IS NULL or IS NOT NULL.
Table employee:
| id | name | dept | salary |
|---|---|---|---|
| 1 | Asha | HR | 40000 |
| 2 | Ravi | IT | 60000 |
| 3 | Meena | IT | 75000 |
| 4 | John | Sales | 50000 |
| 5 | Priya | IT | 60000 |
| 6 | Karan | Sales | NULL |
How many rows does this query return?
SELECT name FROM employee WHERE dept = 'IT';
Enter a number as the answer.
Answer: 3
Three employees work in IT (Ravi, Meena and Priya).
What does this query return for the table below?
Table staff:
| id | name | dept | salary |
|---|---|---|---|
| 1 | Ravi | IT | 50000 |
| 2 | Meena | HR | 40000 |
| 3 | John | IT | 60000 |
| 4 | Sara | Sales | 45000 |
| 5 | Ali | HR | 38000 |
SELECT COUNT(*) FROM staff WHERE dept = 'IT';
2
5
Answer: A
Only Ravi and John are in IT, so COUNT(*) returns 2.
What does this query return for the table below?
Table staff:
| id | name | dept | salary |
|---|---|---|---|
| 1 | Ravi | IT | 50000 |
| 2 | Meena | HR | 40000 |
| 3 | John | IT | 60000 |
| 4 | Sara | Sales | 45000 |
| 5 | Ali | HR | 38000 |
SELECT MAX(salary) FROM staff;
233000
50000
Answer: D
MAX returns the largest salary, John's 60000.
1
3
38000
60000