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.
Monthly savings of ‘Q’ is 20% more than that of ‘P’ and is 48% less than monthly income of ‘P’. Monthly expenditure of ‘Q’ is Rs. 4260 a...
A and B started a business by investing Rs. 1980 and Rs. 3520 respectively. After 18 months, B withdrew his entire investment. At the end of 20 months f...
- If the mean proportion of 1.44 and 2.25 is 'k', then find the value of '5k'.
The ages of A, B and C are in the ratio of 5:4:8 respectively. If the sum of their ages is 51 years, then find the age of B.
If 35% of a certain number is equal to 3/4th of another number, what is the ratio between the numbers?
The ratio of income of A and B is 4:9 and their expenditures are in the ratio of 1:4. If the 40% more than the income of A is equal to the expenditure o...
The mean proportional of 9 and 16 is _____.
A plot has to be divided among P, Q and R in the ratio 3:4:8 respectively. If the area of plot received by R is 5600m² more than the area of plot recei...
What is the fourth proportional to 3, 8, 15?
Monthly savings of ‘Q’ is 25% more than that of ‘P’ and is 44% less than monthly income of ‘P’. Monthly expenditure of ‘Q’ is Rs. 5150 a...