Let’s see a simple example to see, how exactly we can obtain entire employee name who obtains top 10 salaries.
Assuming that we have following table for Employee.
EmpId
| EmpName
| EmpSalary
|
1
| Alok
| 20000
|
2
| Ashok
| 30000
|
3
| Anand
| 25000
|
4
| Akash
| 18000 |
5
| Prasad
| 33000 |
6
| Manoj
| 30000 |
7
| Sachin
| 40000
|
8
| Denish
| 36000
|
9
| Rajesh
| 24000 |
10
| Hari
| 4000
|
11
| Ravi
| 25000
|
12
| Kiran
| 20000
|
13
| Shobha
| 30000 |
14
| Pallavi
| 43000
|
15
| Reshma
| 41000
|
Query:- select Employee.EmpName,Employee.EmpSalary from Employee where Employee.EmpSalary in
(select distinct top(10)Employee.EmpSalary from Employee order by Employee.EmpSalary desc)
OUTPUT:-| EmpName | EmpSalary |
| Alok | 20000
|
| Ashok | 30000 |
Anand
| 25000
|
Akash
| 18000
|
Prasad
| 33000
|
Manoj
| 30000
|
Sachin
| 40000
|
Denish
| 36000
|
Rajesh
| 24000
|
Ravi
| 25000
|
Kiran
| 20000
|
Pallavi
| 43000
|
Reshma
| 41000
|
You will be also interested in watching the below video, which are also asked in most of the interviews and favourable question of interviewers.
Asked In: Many Interviews |
Alert Moderator