Question 31
MediumTable 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 |
What does this query return?
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
DBMS
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 |
What does this query return?
SELECT MAX(salary) FROM employee
WHERE salary < (SELECT MAX(salary) FROM employee);
75000
50000
40000
60000
Sign up free to see the answer and a step-by-step explanation.
What does a LEFT JOIN return?
All rows from the left table, with matching rows from the right table or NULLs where there is no match
Every combination of rows
Only rows that match in both tables
All rows from the right table
Sign up free to see the answer and a step-by-step explanation.
Which is the correct order in which SQL logically processes these clauses?
FROM, SELECT, WHERE, ORDER BY, GROUP BY, HAVING
WHERE, FROM, SELECT, GROUP BY, ORDER BY, HAVING
FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY
SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY
Sign up free to see the answer and a step-by-step explanation.
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 |
What does this query return?
SELECT dept FROM employee
GROUP BY dept
ORDER BY SUM(salary) DESC
LIMIT 1;
IT and Sales
IT
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table orders:
| id | customer | city | amount | status |
|---|---|---|---|---|
| 1 | Ravi | Pune | 1200 | shipped |
| 2 | Meena | Delhi | 800 | pending |
| 3 | Ravi | Pune | 450 | shipped |
| 4 | Kiran | Mumbai | 2000 | cancelled |
| 5 | Meena | Delhi | 1500 | shipped |
| 6 | Arjun | Pune | NULL | pending |
| 7 | Kiran | Mumbai | 700 | shipped |
SELECT customer FROM orders GROUP BY customer HAVING SUM(amount) > 2000 ORDER BY customer;
Kiran, Meena
Kiran, Meena, Ravi
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table orders:
| id | customer | city | amount | status |
|---|---|---|---|---|
| 1 | Ravi | Pune | 1200 | shipped |
| 2 | Meena | Delhi | 800 | pending |
| 3 | Ravi | Pune | 450 | shipped |
| 4 | Kiran | Mumbai | 2000 | cancelled |
| 5 | Meena | Delhi | 1500 | shipped |
| 6 | Arjun | Pune | NULL | pending |
| 7 | Kiran | Mumbai | 700 | shipped |
SELECT COUNT(*), COUNT(amount) FROM orders;
7 | 7
7 | 6
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table orders:
| id | customer | city | amount | status |
|---|---|---|---|---|
| 1 | Ravi | Pune | 1200 | shipped |
| 2 | Meena | Delhi | 800 | pending |
| 3 | Ravi | Pune | 450 | shipped |
| 4 | Kiran | Mumbai | 2000 | cancelled |
| 5 | Meena | Delhi | 1500 | shipped |
| 6 | Arjun | Pune | NULL | pending |
| 7 | Kiran | Mumbai | 700 | shipped |
SELECT AVG(amount) FROM orders WHERE city = 'Pune';
550.0
NULL
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table orders:
| id | customer | city | amount | status |
|---|---|---|---|---|
| 1 | Ravi | Pune | 1200 | shipped |
| 2 | Meena | Delhi | 800 | pending |
| 3 | Ravi | Pune | 450 | shipped |
| 4 | Kiran | Mumbai | 2000 | cancelled |
| 5 | Meena | Delhi | 1500 | shipped |
| 6 | Arjun | Pune | NULL | pending |
| 7 | Kiran | Mumbai | 700 | shipped |
SELECT city, COUNT(*) FROM orders WHERE status <> 'cancelled' GROUP BY city ORDER BY city;
Delhi | 2, Mumbai | 2, Pune | 3
Delhi | 2, Mumbai | 1, Pune | 3
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table orders:
| id | customer | city | amount | status |
|---|---|---|---|---|
| 1 | Ravi | Pune | 1200 | shipped |
| 2 | Meena | Delhi | 800 | pending |
| 3 | Ravi | Pune | 450 | shipped |
| 4 | Kiran | Mumbai | 2000 | cancelled |
| 5 | Meena | Delhi | 1500 | shipped |
| 6 | Arjun | Pune | NULL | pending |
| 7 | Kiran | Mumbai | 700 | shipped |
SELECT COUNT(DISTINCT customer) FROM orders WHERE status = 'shipped';
4
5
Sign up free to see the answer and a step-by-step explanation.
What does this query return for the table below?
Table orders:
| id | customer | city | amount | status |
|---|---|---|---|---|
| 1 | Ravi | Pune | 1200 | shipped |
| 2 | Meena | Delhi | 800 | pending |
| 3 | Ravi | Pune | 450 | shipped |
| 4 | Kiran | Mumbai | 2000 | cancelled |
| 5 | Meena | Delhi | 1500 | shipped |
| 6 | Arjun | Pune | NULL | pending |
| 7 | Kiran | Mumbai | 700 | shipped |
SELECT id FROM orders WHERE amount > (SELECT AVG(amount) FROM orders) ORDER BY id;
4, 5
1, 4, 5
Sign up free to see the answer and a step-by-step explanation.
Sales
HR
Meena
Kiran
6 | 6
6 | 7
825.0
1650.0
Delhi | 2, Mumbai | 1, Pune | 2
Pune | 3, Delhi | 2, Mumbai | 1
3
2
1, 4, 5, 6
1, 2, 4, 5