Question: I want to fetch all the photos on Google photos on my web site using php. 
Is it possible?. I know Picasa Web Albums Data API deprecated. I have got try it from Picasa. but i am not able to download library from <https://developers.google.com/gdata/articles/php_client_lib>.

Answer: 
**a) Write a Query to find least 5th (Least salary in 5th position from least salary in the order) salaried employee?**

```
SELECT EMPID,NAME,DEPTID,SALARY
FROM
(
SELECT EMPID,NAME,DEPTID,SALARY, DENSE_RANK() OVER (ORDER BY SALARY) AS RN
FROM Table1
) 
WHERE RN=5

```

**b) Query to find the highest earning employee in each department**

```
SELECT EMPID,NAME,DEPTID,SALARY
FROM
(
SELECT EMPID,NAME,DEPTID,SALARY, 
  DENSE_RANK() OVER (PARTITION BY DEPTID ORDER BY SALARY DESC) AS RN
FROM Table1
)
WHERE RN=1

```

Demo

> 
> <http://sqlfiddle.com/#!4/63ce0/12>
> 
> 
>
Let's assume we have a table named `EmployeeSalary` which has 3 columns: 

1. Id
2. Name
3. Salary

Salary might be same for multiple employee according to the following table data

```
Id  Name    Salary
----------
6   Belalo  74
1   Karim   100
5   dIPU    100
4   Satter  102
9   Kiron   120
10  Rash    120
11  Harun   130
13  Baki    130
12  Munshi  132
2   Rahim   500
7   Kaif    987
8   Sony    987
3   Belal   4000

```

Now the query will be

```
SELECT A.Salary
FROM
(
SELECT DISTINCT Salary, 
DENSE_RANK() OVER (ORDER BY Salary) AS Ranks
FROM [dbo].[EmployeeSalary]
) A 
WHERE A.Ranks=5

```