Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: Basic SQL Q...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 10987 of 11517
Post > Topic >>

Re: Basic SQL Question

by Iain Sharp <iains@[EMAIL PROTECTED] > Apr 22, 2008 at 04:26 PM

On Tue, 22 Apr 2008 08:11:07 -0700 (PDT), t8ntboy <t8ntboy@[EMAIL PROTECTED]
>
wrote:

>I cannot figure out why this is not working.  For some reason the
>following statement is yielding multiple records with the same CESAFID
>eventhough it is supposed to be grouped.
>
>The query is intended to find the most recent record status date
>(GoStatusDate) and record status (GoStatus).
>
>Please help!
>
>SELECT     CESAFID, MAX(GoStatusDate) AS GoStatDate, GoStatus
>FROM         dbo.Go_Re****t
>GROUP BY CESAFID, GoStatus

You patently have more than on GOStatus for the same CESAFID, so the
group by GoStatus is wrong. 

You need something like 

select CESAFID, gostatusdate, gostatus
from dbo.GO_Re****t a
 where a.gostatusdate = (select max(b.gostatusdate) from dbo.go_re****t
b where a.cesafid = b.cesafid)
 




 2 Posts in Topic:
Basic SQL Question
t8ntboy <t8ntboy@[EMAI  2008-04-22 08:11:07 
Re: Basic SQL Question
Iain Sharp <iains@[EMA  2008-04-22 16:26:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 22:06:01 CST 2008.