Reputation: 17
Hello friends I am stuck in writing one query.
Can you please help me out?
I have one table called prog
and having column doj
.
Here in name
column I have name of all employee and in doj
column I have their date of joining.
I have to find out the name of least experienced employee so I write this query to find the least experienced employee using their date of joining:
SELECT
min(DATEDIFF(YEAR,doj,GETDATE()) -
(CASE WHEN
DATEADD(YY,DATEDIFF(YEAR,doj,GETDATE()),doj) > GETDATE()
THEN 1
ELSE 0 END)) AS 'least experience'
FROM programmer
I am not able to find out the name
of employee.
If I use the column name
with group by
the I get list of all employee with their name and year of experience.
How can I find out the name of only that particular employee having least experience.
Thanks in advance and waiting for reply.
Upvotes: 0
Views: 2904
Reputation: 3114
This will select the programmer with the most recent start date.
Select top 1 name, doj
from programmer
order by doj desc
Upvotes: 7