You are here: Re: Max(date) using joins « MsSQL Server « IT news, forums, messages
Re: Max(date) using joins

Posted by Plamen Ratchev on 09/30/36 12:00

I think your query returns the same results only by coincidence. If you have
only the following rows in table SAF2_Status:

Course | Status | Action Date
--------- ---------------- ----------------
1111 DEPTQUEUE Jan-1-2008
1111 DEPTRMVLST Jan-5-2008

Then your query will return course 1111 because 'Jan-1-2008' is the latest
date according to your subquery conditions and it satisfies the WHERE
conditions. And this is incorrect according to your requirements.

Your query may return the correct results if you have another row like below
(and you probably have such rows, which is the reason you see the results
matching):

Course | Status | Action Date
--------- ---------------- ----------------
1111 DEPTABCDE Jan-3-2008

Note, it is another code not in the list ('DEPTSETUP', 'DEPTQUEUE',
'CERTRN', 'DEPTCORRREQ') which now has the latest Action Date because code
'DEPTRMVLST' is excluded.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация