TGTGInsighttelegram intelligenceLIVE / telegram public index
← Data Analytics
Data Analytics avatar

TGINSIGHT POST

Post #2448

@sqlspecialist

Data Analytics

Views11,100Post view count
PostedDec 212/02/2025, 08:10 AM
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!