Question
Which of the following SQL queries will return the
second highest salary from a table Employee with columns Name and Salary?Solution
This query uses a subquery to find the maximum salary and excludes it using NOT IN. The outer query then finds the maximum salary among the remaining values, effectively identifying the second highest salary. • Why this works: The subquery isolates the highest salary. The outer query ensures the second highest value is identified without requiring an OFFSET. This method works across most SQL systems and avoids platform-specific syntax like LIMIT or TOP. ________________________________________ Why Other Options Are Incorrect: 1. LIMIT 2: Returns two highest salaries but doesn’t isolate the second highest. 2. OFFSET 1: Many SQL platforms do not support LIMIT ... OFFSET or require modifications for accurate execution. 3. DISTINCT Salary: Redundant use of DISTINCT, which is unnecessary when ORDER BY already ensures unique ordering. 4. TOP 2: TOP is SQL Server-specific and requires additional filtering for the second value.
How many males work in the Accounts department?
If ratio of male to female in Operation is 5:3, then total male employees in Operation are what percent of total employees in HR?
Find the average speed of boat A to cover the given distance if the speed of boat A in still water is 20km/hr?
What is average number of female doctors of hospital A, B and C together?
What percentage more are the number of jasmine flowers in Garden 'C' compared to the number of rose flowers there?
Find the value of [P] – [S].
What is the ratio between the sum of the number of girls and boys in school A and the number of teachers in school C?
Find the number of female employees working in company C.
Find the ratio of the number of female of tribe Raba and Dimasa.
If the boutique decides to offer a discount of 15% on Designer Dresses during a promotional sale and they sell 80 units at this new price, Calculate the...