Write a query to find the second highest salary.

Quality Thought – Best Data Science Training Institute in Hyderabad with Live Internship Program

If you're aspiring to become a skilled Data Scientist and build a successful career in the field of analytics and AI, look no further than Quality Thought – the best Data Science training institute in Hyderabad offering a career-focused curriculum along with a live internship program.

At Quality Thought, our Data Science course is designed by industry experts and covers the entire data lifecycle. The training includes:

Python Programming for Data Science

Statistics & Probability

Data Wrangling & Data Visualization

Machine Learning Algorithms

Deep Learning with TensorFlow and Keras

NLP, AI, and Big Data Tools

SQL, Excel, Power BI & Tableau

What makes us truly stand out is our Live Internship Program, where students apply their skills on real-time datasets and industry projects. This hands-on experience allows learners to build a strong project portfolio, understand real-world challenges, and become job-ready.

Why Choose Quality Thought?

✅ Industry-expert trainers with real-time experience

✅ Hands-on training with real-world datasets

✅ Internship with live projects & mentorship

✅ Resume preparation, mock interviews & placement assistance

✅ 100% placement support with top MNCs and startups

Whether you're a fresher, graduate, working professional, or career switcher, Quality Thought provides the perfect platform to master Data Science and enter the world of AI and analytics.

📍 Located in Hyderabad | 📞 Call now to book your free demo session and take the first step toward a data-driven future!.

To find the second highest salary in SQL, you can use several approaches depending on the database system.

🔹 Using LIMIT / OFFSET (MySQL, PostgreSQL):

SELECT DISTINCT salary FROM Employees ORDER BY salary DESC LIMIT 1 OFFSET 1;
  • ORDER BY salary DESC sorts salaries in descending order.

  • OFFSET 1 skips the highest salary.

  • LIMIT 1 fetches the next (second highest).

🔹 Using TOP with NOT IN (SQL Server, Oracle with ROWNUM):

SELECT MAX(salary) AS second_highest FROM Employees WHERE salary < (SELECT MAX(salary) FROM Employees);
  • Finds the maximum salary less than the overall maximum.

🔹 Using Window Functions (preferred in modern SQL):

SELECT salary FROM ( SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk FROM Employees ) ranked WHERE rnk = 2;
  • DENSE_RANK() assigns ranks without skipping for duplicate salaries.

  • Fetches all salaries ranked 2, handling ties properly.

Summary:

  • Use LIMIT & OFFSET for simple cases.

  • Use subquery with MAX for older DBs.

  • Use window functions for modern, efficient, and tie-safe solutions.

Read More :


Visit  Quality Thought Training Institute in Hyderabad       

Comments

Popular posts from this blog

What is a primary key and foreign key?

What is label encoding?

What is normalization in databases?