Question
Which of the following SQL queries is used to find the
second highest salary from an employee table? SELECT MAX (salary) Â Â Â Â Â Â Â FROM employee WHERE salary < ( SELECT MAX (salary) FROM employee);Solution
The query uses a nested SELECT statement to retrieve the second-highest salary from the employee table. Let's break it down:
- Inner query: SELECT MAX(salary) FROM employee retrieves the highest salary in the employee table.
- Outer query: The WHERE salary < (SELECT MAX(salary) FROM employee) ensures that only those salaries smaller than the highest salary are considered, and the outer MAX(salary) retrieves the largest salary from that set, effectively giving the second-highest salary.
- B is incorrect because the query does not return the highest salary but rather the second-highest salary by excluding the maximum salary.
- C is incorrect because nested SELECT statements are valid in SQL and do not cause errors here.
- D is incorrect because the query will return a value unless there are no records in the employee table.
- E is incorrect because the query will return a single value—the second-highest salary.
In a certain school, 60% of the students are girls, and the rest are boys. If the number of boys in the school is 480, how many students are there in to...
In a company with a total of 450 employees, 270 are men, and the remaining are women. It is known that 60% of the women are employed in the marketing de...
'Q' spends 25% of his monthly income on rent, 40% on groceries, and 15% of the remaining amount on entertainment. He saves the rest of the money in a fi...
Ravi scored 80 marks in English. He scored 66% marks in Hindi and X marks in Maths. The maximum marks for each subject is 200. The overall percentage of...
'X' scored 236 marks in Maths and failed by 64 marks as passing percentage is 40%. How many marks he needs to score to get 70% marks in Maths?
Ravi spends 75% of his monthly salary. If his monthly savings are Rs 6,500, what is his monthly salary?
The marks scored by a student in three subjects are in the ratio 4 : 5 : 6. Student scored an overall aggregate of 40% in the exam. If the maximum marks...
80% of a number is equal to 60% of another number. If the total of both numbers is 560, find the difference between them.
A student has to obtain 35% of the total marks to pass. He got 214 marks and failed by 31 marks. What are the maximum marks?
The population of a city is decreased by 20% in the first year and then increased by 32% in the second year. Find the population of the city at the end...