How would you write a SQL query to find the second highest salary from a table?
- SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);
- SELECT TOP 2 salary FROM employees ORDER BY salary DESC;
- SELECT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;
- SELECT salary FROM employees ORDER BY salary DESC LIMIT 1, 1;
To find the second highest salary, you can use the ORDER BY clause in descending order and apply LIMIT with an offset of 1 to retrieve the second highest salary from the table.
Loading...
Related Quiz
- What is the primary difference between an integer and a float data type in most programming languages?
- Which algorithm would be most appropriate for forecasting future sales based on historical data?
- In a typical database, what data type is commonly used to store large text such as comments or descriptions?
- How does the principle of 'small multiples' aid in comparative data analysis?
- In a sales report spreadsheet, if you need to identify trends over several months, which Excel feature would be most effective?