Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 find the first row

Author  Topic 

nbalraj
Starting Member

21 Posts

Posted - 2011-11-08 : 16:24:35
Hi All

below is the table records

11/08/2011 John Doe
10/08/2011 John Doe
02/08/2011 John Doe
11/10/2011 Mary Fine
05/10/2011 Mary Fine
01/10/2011 Mary Fine

I need only the max row

11/08/2011 John Doe
11/10/2011 Mary Fine

How can i get this. Thanks for any help.




Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-11-08 : 16:52:17
[code]SELECT MIN(<Date Column>), <Name Column>
FROM <Table Name>
GROUP BY <Name Column>[/code]
Go to Top of Page

nbalraj
Starting Member

21 Posts

Posted - 2011-11-08 : 17:06:12
sorry, i forgot to add one more condition

below is the updated table records

11/08/2011 John Doe elec
10/08/2011 John Doe mechanical engg
02/08/2011 John Doe prod engg
11/10/2011 Mary Fine engg
05/10/2011 Mary Fine mech
01/10/2011 Mary Fine prd

I need only the max row

11/08/2011 John Doe elec
11/10/2011 Mary Fine engg

How can i get this. Thanks for any help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-09 : 01:07:44
[code]
SELECT t.*
FROM table t
INNER JOIN (SELECT MAX(DateField) AS MaxDate,Namefield
FROM table
GROUP BY nameField) t1
ON t1.NameField = t.NameField
AND t1.MaxDate = t.DateField
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -