Click here to Skip to main content
15,881,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I have salary table as below columns.

Emp_Id Name Salary

How do i write one query which give me questioned result.

Thanks!

What I have tried:

select Name, MIN(Top 2 Salary) from Salary;
Posted
Updated 21-Jan-19 6:57am
v2

try this
select Top 2 Name,Emp_Id,Salary from Salary order by salary asc
 
Share this answer
 
Comments
Member 14124697 21-Jan-19 8:42am    
above syntax is not working on ORACLE SQL.
CHill60 21-Jan-19 9:49am    
Now here is the "thing" … if you want a solution for Oracle you must tag your question as "Oracle"
Member 14124697 21-Jan-19 12:30pm    
Can you please give me solution for oracle.?
CHill60 21-Jan-19 13:47pm    
I have posted a solution
Santosh kumar Pithani 22-Jan-19 3:43am    
How you decide my solution is not work for oracle,have you tried to execute?
SQL
CREATE TABLE #EMP(Emp_Id INT, Name VARCHAR(20),Salary MONEY)
INSERT INTO #EMP(Emp_Id,Name,Salary)
VALUES
(1215 ,'Harish',20000),
(1234,'sai',30000    ),
(1245 ,'Satish',15000),
(1246 ,'santosh',20000);

;WITH CTE AS(
    SELECT * ,DENSE_RANK()OVER(ORDER BY Salary) AS DN FROM #EMP
            )

SELECT 
   Emp_Id
  ,Name
  ,Salary 
FROM CTE WHERE DN in(1,2)

OUTPUT:-
-----------------------
Emp_Id| Name | Salary
-----------------------
1245	Satish	15000.00
1246	santosh	20000.00
1215	Harish	20000.00
 
Share this answer
 
As requested by OP...
Oracle / PLSQL: Retrieve Bottom N records from a query[^]
First result on this Google[^] search
 
Share this answer
 
Comments
Member 14124697 21-Jan-19 14:02pm    
Thanks.....now this helps me to get my answer...

Many thanks..
CHill60 29-Jan-19 10:58am    
I notice that you have removed the "Accept Solution" from this. Does this mean that it did not solve your problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900