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
 select statements

Author  Topic 

maryfsan
Starting Member

1 Post

Posted - 2012-04-11 : 21:52:53
Hi. This seems like it should be simple. I am trying to find the latest year for each company.
Sample data:
Company Fiscal Year
AAA 2008
AAA 2009
AAA 2010
BBB 2008
BBB 2009
CCC 2011
CCC 2010

Desired output:
AAA 2010
BBB 2009
CCC 2011

I am running SQL Server 2008 R2. I've tried various combinations of things but it's clear I don't under the logic of SELECT.
Thanks.


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-04-11 : 22:05:25
[code]
SELECT Company, MAX(FixcalYear)
FROM YourTable
GROUP BY Company
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-12 : 00:25:55
hope you dont want to return any other fields from table if it exists

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

Go to Top of Page

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-04-12 : 06:08:03
Yup!!...was as simple as that.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page
   

- Advertisement -