TGTGInsighttelegram intelligenceLIVE / telegram public index
Post content
Post content
πππ»ππ²πΏππΆπ²ππ²πΏ: How do you get the 2nd highest salary in SQL? ππ π²: Use ORDER BY with LIMIT or OFFSET, or a subquery. MySQL / PostgreSQL (with LIMIT & OFFSET): SELECT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1; Using Subquery (Works on most databases): SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees); π§ Logic Breakdown: - First method sorts and skips the top result - Second method finds the highest salary below the max π‘Tip: Use DENSE_RANK() if multiple employees share the same salary rank π¬Tap β€οΈ for more!