Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SalId EmpId TakenSal TakenDate AvailSal CompanyId
13 68 1000 02-Jul-2015 29000 1021
14 68 100 02-Jul-2015 28900 1021
15 69 1000 02-Jul-2015 23000 1021
16 82 1000 06-Jul-2015 19000 1024
17 82 1000 06-Jul-2015 18000 1024
18 83 1000 06-Jul-2015 19000 1024
19 83 1000 06-Jul-2015 18000 1024
20 82 1000 06-Jul-2015 17000 1024
21 82 1000 06-Jul-2015 16000 1024
22 82 1000 06-Jul-2015 15000 1024
23 82 1000 06-Jul-2015 14000 1024
24 94 1000 09-Jul-2015 19000 1014
25 94 1000 09-Jul-2015 18000 1014
26 94 1000 09-Jul-2015 17000 1014
27 94 1000 09-Jul-2015 18000 1014

How do I get 68,69,82,83,94 employees last records in sql?
Posted

Order by SalId descending and then use the TOP keyword to get the topmost row.
This will be your last record!
 
Share this answer
 
Comments
Dawood507 27-Oct-15 2:13am    
I dnt want one last record...I want last records of every employees..
SQL
select em.* from employees em join (
select max(SalId) as SalId,EmpId from employees
group by EmpId) as s on em.SalId = s.SalId and em.EmpId = s.EmpId


or

select * from [tbl_emps] where [alId] in( SELECT max(alId) FROM [tbl_emps] group by empid ) 
 
Share this answer
 
Try like below
SQL
SELECT * FROM
(SELECT EmpId,SalId,
DENSE_RANK() OVER (PARTITION BY SalId ORDER BY EmpId DESC) AS RNK
FROM @EMP ) AS A
WHERE A.RNK=1
 
Share this answer
 
Hope below query will help you

SQL
select * from Table_Name where SalID in (
select Max(SalID) as SalID from Table_Name where EmpID in (68,69,82,83,94)
group by EmpID)
 
Share this answer
 

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