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.
India handed over_______ tonnes fertilizer to Sri Lanka recently?
In which medium is the speed of sound the highest?
According to the data provided by the Centre for Monitoring Indian Economy ,all India unemployment rate remained elevated in February 2023 and rose to__...
What is the objective of the SHRESHTA (Residential Education for Students in High Schools in Targeted Areas) scheme recently approved by the government?
Which country’s King Willen -Alexander opened the world's largest canal lock, Zeesluis IJmuiden.
The Reserve Bank of India (RBI) has imposed late submission fees (LSF) of ₹2,000 crore on ONGC Videsh Ltd (OVL), Indian Oil Corp. Ltd, GAIL (India) Lt...
What is the effective date for the higher D - SIB buffer requirements for State Bank of India ( SBI ) and HDFC Bank?
France has recently announced a ban on children wearing the Abaya, a loose-fitting, full-length robe, in state-run schools. What is the primary reason c...
What is the IMF’s revised GDP growth forecast for India for FY26?
Economist Intelligence Unit (EIU) released the Democracy Index 2021. What is India’s rank on the global index?