Question
Which SQL query will retrieve the second highest salary
from an Employee table?Solution
This query correctly retrieves the second-highest salary by first finding the maximum salary and then searching for the maximum salary that is less than the first maximum. The subquery (SELECT MAX(Salary) FROM Employee) retrieves the highest salary, and the main query finds the maximum salary that is smaller than that value, effectively returning the second-highest salary. This method ensures that the second-highest salary is retrieved by eliminating the highest salary and then finding the next largest value. Why Other Options Are Incorrect:
- B) This query would retrieve the third-highest salary, not the second-highest, due to the OFFSET 2 . It skips the first two salaries, resulting in the third.
- C) This query retrieves the highest salary, not the second-highest, by selecting the maximum salary without any condition.
- D) This query retrieves all salaries greater than the average salary, which does not necessarily provide the second-highest salary. It is based on a statistical average, not ranking.
- E) This query correctly retrieves the second-highest salary but uses LIMIT 2,1 , which might be seen as non-standard across different SQL systems. The approach is less elegant than option A for finding the second-highest salary.
Two similar triangles have areas 50 cm² and 98 cm². If a side of the smaller triangle is 5 cm, find the corresponding side of the larger triangle.
The perimeter of an equilateral triangle is 48√3 cm. Find its height.
Calculate the hypotenuse of an isosceles right-angled triangle where the equal sides are 8√6 cm each.
Calculate the altitude of an equilateral triangle having each side of length 10√3 cm.
In a ∆ABC, angle BAC = 90°. If BC = 25 cm, then what is the length of the median AD?
What is the height of an equilateral triangle with a side length of 14√7 cm?
In triangle ABC, DE is drawn parallel to BC, intersecting AB at D and AC at E. If AD : DB = 2 : 1 and area of triangle ADE is 24 cm², find:
(i) ...
In a triangle ABC, the incenter is at O. Find angle BAC if angle BOC=120°.
A triangular plot of land has sides 15 m, 20 m, and 25 m. Find its area and the cost of fencing it along all sides at Rs 80 per metre
Determine the inradius of an equilateral triangle whose altitude measures 9√3 cm.