SQL Query to Find Employees With Same Salary (4 Ways)

SQL Query to Find Employees With Same Salary

A compensation team is preparing a pay-equity review, and someone asks a simple question: “Which employees earn exactly the same salary?” The analyst exports the table to Excel, builds a pivot, and misses half the matches because two names were stored with different spacing. The same question takes seconds in the database, if you write … Read more

How to find highest paid Employee in SQL

How to find highest paid Employee in SQL

A finance analyst runs a quick query to pull the top earner for a budget review. The query returns one name, but two people share that salary, and a third employee with a NULL salary quietly slipped into the sort. The report goes to leadership, and the next day somebody asks why the second person … Read more

How to Find Maximum Salary in SQL

How to Find Maximum Salary in SQL

A finance analyst once sent me a screenshot of a payroll report with a cheerful note: “Highest salary is 95,000.” The CFO had just approved an offer at 140,000, so the number looked wrong. The report’s salary column had been imported as text. SQL Server compared the values as strings, and “95000” sorted above “140000” … Read more

How to Get Top 5 Highest Salary in SQL

How to Get Top 5 Highest Salary in SQL

A few years ago, an HR team at a mid-size U.S. retailer asked me why their “top 5 earners” report showed seven people on some days and four on others. The developer had used a simple TOP 5 query. Two employees shared the same salary at the cutoff, and the report silently dropped one of … Read more

ROW_NUMBER vs RANK vs DENSE_RANK in SQL

ROW_NUMBER vs RANK vs DENSE_RANK in SQL

Understanding row_number vs rank vs dense_rank in SQL is one of the highest-value skills for anyone writing T-SQL reports. These three window functions look nearly identical, yet they produce different results the moment two rows share a value. Picking the wrong one causes duplicate invoice numbers, missing rows, and reports that change between runs. This … Read more

How to Find the Top 3 Employees by Salary in SQL Server

How to Find the Top 3 Employees by Salary in SQL Server

A few years ago, an HR analyst at a logistics company asked me why her “top 3 earners” report showed three people one week and five the next. Nothing in the data had changed. Two employees shared the same salary, and the query she copied from a forum quietly cut off one of them. Leadership … Read more

DENSE_RANK SQL

DENSE_RANK SQL

A payroll dashboard skips second place after two employees share the highest salary. Another report forces those same employees into different positions. Both queries run without errors, but neither matches the business requirement: equal salaries should share a rank, with no gaps afterward. The DENSE_RANK SQL function solves that problem. It assigns consecutive ranks to … Read more

How to Find the Second Lowest Salary in SQL Server

How to Find the Second Lowest Salary in SQL Server

A payroll report lists the lowest-paid employee twice because two people earn the same amount. A developer skips the first row to find the second-lowest salary, but the query returns that same minimum again. The statement runs successfully; the business answer is wrong. Understanding how to find the second lowest salary in SQL Server starts … Read more

How to Find the Lowest Salary in SQL Server

How to Find the Lowest Salary in SQL Server

A payroll dashboard shows the lowest salary as zero, but HR says no active employee earns that amount. The query runs successfully. The problem is that it mixes placeholder values, inactive employees, and legitimate salaries without defining which records belong in the report. Knowing how to find the lowest salary in SQL Server starts with … Read more

How to Find 3rd Highest Salary in SQL Server

How to Find 3rd Highest Salary in SQL Server

A payroll report can return the wrong employee even when its SQL runs without errors. Two employees share the highest salary, and a query that simply selects the third row reports the second-highest salary instead of the third distinct amount. Understanding how to find 3rd highest salary in SQL Server starts with defining what “third … Read more