开发者

Select distinct of a date along with other fields from a table

开发者 https://www.devze.com 2022-12-13 17:04 出处:网络
In the table \'Emplyoee\' there are two fields-JoinDate and EmployeeName.开发者_Go百科 All Data contains in Emplyoee table is as follows:

In the table 'Emplyoee' there are two fields-JoinDate and EmployeeName.开发者_Go百科

All Data contains in Emplyoee table is as follows:

JoinDate      | EmployeeName
------------------------
02-12-2009   Vijay

03-12-2009   Binoy

03-12-2009   Rahul

My select query is as follows:

SELECT DISTINCT JoinDate,EmployeeName FROM Emplyoee

I got the Result as follows:

JoinDate   | EmployeeName
------------------------
02-12-2009   Vijay
03-12-2009   Binoy
03-12-2009   Rahul

But i need the result as follows:

JoinDate   | EmployeeName
------------------------
02-12-2009   Vijay
03-12-2009   Binoy(first employee joined on this date)


This will select the first employee alphabetically that joined on each date:

 SELECT DISTINCT mydates.JoinDate, 
    (SELECT TOP 1 EmployeeName FROM Employee e2 WHERE e2.JoinDate=mydates.JoinDate ORDER BY EmployeeName)
 FROM Employee mydates
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号