Write a query to find the second highest salary in a table.

Best Data Analyst Course Training Institute in Hyderabad

Shyam Technologies is recognized as one of the best institutes in Hyderabad for comprehensive Data Analyst training. With the increasing demand for data-driven decision-making in businesses, our program is designed to equip students, fresh graduates, and working professionals with in-depth knowledge and practical skills in data analysis.

Our Data Analyst course covers essential topics such as data collection, cleaning, and visualization, along with advanced tools like Excel, SQL, Python, and Tableau. Students gain expertise in data manipulation, creating meaningful insights, and generating actionable business reports. The course emphasizes hands-on learning with real-time datasets, preparing learners for the dynamic demands of the industry.

A unique feature of Shyam Technologies is our Live Intensive Internship Program, which offers students the opportunity to work on real-world projects under expert mentorship. This internship bridges the gap between classroom learning and practical industry experience. Participants engage in tasks such as analyzing business metrics, building dashboards, and performing predictive analysis. By the end of the program, students not only enhance their technical skills but also develop a strong portfolio, boosting their employability.

Our trainers are experienced professionals with years of industry expertise in data analysis. Alongside technical training, Shyam Technologies provides career support, including resume building, interview preparation, and placement guidance. Many of our alumni have successfully secured positions in leading companies, making Shyam Technologies a trusted name for data analytics training in Hyderabad.

If you are looking for the best Data Analyst course in Hyderabad that combines expert teaching with a live internship, Shyam Technologies is your ideal choice. Start your journey towards becoming a skilled data analyst and unlock exciting career opportunities in the world of data with us today!

Here’s a common way to find the second highest salary in a table named employees with a column salary:

Method 1: Using LIMIT and ORDER BY (MySQL, PostgreSQL, etc.)

SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;
  • ORDER BY salary DESC sorts salaries from highest to lowest.

  • DISTINCT ensures duplicate salaries are ignored.

  • LIMIT 1 OFFSET 1 picks the second row (second highest salary).

Method 2: Using a Subquery

SELECT MAX(salary) AS second_highest_salary FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);
  • The inner query finds the highest salary.

  • The outer query finds the maximum salary less than the highest, giving the second highest.

Method 3: Using ROW_NUMBER() (SQL Server, Oracle, PostgreSQL)

WITH salary_rank AS ( SELECT salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn FROM employees ) SELECT salary AS second_highest_salary FROM salary_rank WHERE rn = 2;
  • ROW_NUMBER() assigns a unique rank to salaries in descending order.

  • Selecting rn = 2 gives the second highest salary  

Comments

Popular posts from this blog

What is the difference between INNER JOIN, LEFT JOIN, and RIGHT JOIN?

Explain normalization and denormalization in databases.

How would you optimize a slow-running SQL query?