********************Youngest & Oldest Employee********************
To get the youngest / olderst employee, two different methods are shown here.
1. Using Max and Min Functions
2. Using Top in Select Statement
'' Youngest Employee (Reference : AdventureWorks)
Select Min(BirthDate) from HumanResources.Employee
Select TOP 1 BirthDate from HumanResources.Employee Order By 1 Asc
Select TOP 1 * from HumanResources.Employee Order By BirthDate Asc
Select * from Person.Contact where ContactID = (Select TOP 1 EmployeeID from HumanResources.Employee Order By BirthDate Asc)
'' Oldest Employee (Reference : AdventureWorks)
Select Max(BirthDate) from HumanResources.Employee
Select TOP 1 BirthDate from HumanResources.Employee Order By 1 Desc
To get the youngest / olderst employee, two different methods are shown here.
1. Using Max and Min Functions
2. Using Top in Select Statement
'' Youngest Employee (Reference : AdventureWorks)
Select Min(BirthDate) from HumanResources.Employee
Select TOP 1 BirthDate from HumanResources.Employee Order By 1 Asc
Select TOP 1 * from HumanResources.Employee Order By BirthDate Asc
Select * from Person.Contact where ContactID = (Select TOP 1 EmployeeID from HumanResources.Employee Order By BirthDate Asc)
'' Oldest Employee (Reference : AdventureWorks)
Select Max(BirthDate) from HumanResources.Employee
Select TOP 1 BirthDate from HumanResources.Employee Order By 1 Desc
3 comments:
can u get oldest and youngest with 1 select? and how
Try this to display youngest employee from each native place:
select p.Nativeplace, p.Name, p.Dobirth from personal p
having p.Dobirth=(select max(Dobirth) from personal p2
where p.Nativeplace=p2.Nativeplace group by p2.Nativeplace);
OLDEST EMployee
select FirstName as [oldest] from Employee where dob in (
select min(dob) from Employee )
Post a Comment