Skip to main content

Posts

Showing posts with the label SQL Nth Highest salary
Find nth highest salary- SQL Suppose that you are given the following simple database table  called Employee that  has 2 columns named Employee ID and Salary: Employee Employee ID Salary 3 200 4 800 7 450 Write a SQL query to get the second highest salary from the table  above. Also write a query to find the nth highest salary in SQL,  where n can be any number. The easiest way to start with a problem like this is to ask yourself a simpler question first. So, let’s ask  ourselves how can we find the  highest  salary in a table? Well, you probably know that is actually really  easy – we can just use the MAX aggregate function: select MAX(Salary) from Employee; Remember that SQL is based on set theory You should remember that SQL uses  sets  as the foundation for most of its queries. So, the question i s how can we use set theory to find the 2nd highest salary in the table above? Think about it on your...