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.
A trader allows two successive discounts of 20% and 10% on selling an article. If he gets 550 for that article, find its marked price.
A debtor can pay 78 paise in the rupee, but if his creditors would take 25% of his debts, he could pay them and have Rs 48 left. His debts and assets r...
On selling an item for Rs. 900, the profit earned by the seller is 20% more than the profit earned on selling the same item for Rs. 850. If the seller a...
A sold a watch to B at a profit of 20%. B sold it to C at 30% profit. C sold it to D at 10% loss. If B's profit is ₹.80 more than that of A, then D bo...
Profit percentage received on a product when sold for Rs.550 is equal to the percentage loss incurred when the same product is sold for Rs.420. Find the...
A sold an article at 35% profit. If the profit earned had been 260% more, then the profit percentage would have been numerically equal to CP. Find the a...
An article is sold at a price that is 40% higher than its cost price. After offering a discount of Rs. 116, the seller still makes a profit of 24%. Wha...
The ratio between the marked price and cost price of an article is B:A respectively. The ratio between the selling price and marked price of the article...
A shopkeeper purchased two articles, P and Q at Rs 200 each. He sold article P and Q at a profit of Rs 40 and Rs 50 respectively. He also offered a disc...
A purse is sold for 12/25 of its marked price, yielding a profit of 20%. What is the ratio of the marked price to the cost price?