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 was the percentage increase in India's outward foreign direct investment (FDI) commitments in January 2024 compared to January 2023?
Mera Hou Chongba, a festival symbolizing unity and nationalism, is predominantly celebrated in which Indian state?
Who emerged victorious in the men's singles final of the Tennis Chennai Open ATP Challenger held on February 11, 2024?
Outlook Group has launched its highly anticipated retirement planning event, "40After40" in association with which bank shop for all conversations aro...
Recently insurance regulator IRDAI has mandated that all policyholders must provide their _____ details when purchasing any type of insurance policy fro...
The Reserve Bank of India has approved _______ of surplus transfer to the government for 2022-23 and has maintained the contingency risk buffer 50 basis...
What is the name of the innovative whatsapp chatbot platform that facilitates easy and hassle-free train travel, allowing users to book train tickets, c...
Which mission was highlighted for its role in recycling critical minerals as part of India's clean energy transition?
Recently Maharashtra has decided to set up a “Gene Project Bank”. It will be on which of the following theme/themes?
Who has been appointed as the Director General of the National Investigation Agency (NIA) as of 2024?