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.
What is the limit of number of select group of persons who can be identified by the Board for offer of securities or invitation to subscribe securities ...
Which ISO standard is related to quality management system?
Who formulates and announces foreign trade policy?
What are Eligible Companies as per the Companies Act?
Under what article of the Constitution of India can the President take over the administration of a state in case its constitutional machinery breaks down?
Article 368 (Part XX) grants Parliament power to amend the Constitution. Which statement about Article 368 is CORRECT after judicial interpretation?
Under Section 4 of the Payment and Settlement Systems Act, 2007, which of the following correctly states the requirement for operating a payment system ...
As per Explanation 5 of Section 46 of BNS, in abetment by conspiracy, which of the following is not necessary?
For the purpose of examination of a person, a court can issue commission to - another court
Section 3(2)(iv) of the Environment (Protection) Act, 1986 specifically empowers laying down standards for: