Reply to Re: Can it be done ?

Your name:

Reply:


Posted by Stefan Rybacki on 04/01/06 17:29

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

strawberry schrieb:
> OK, so the correct answer should be:
>
> SELECT pr.propertyid, pr.valuationdate, pr.valuation
> FROM properties pr, (
>
> SELECT max( valuationdate ) AS maxdate, propertyid
> FROM properties
> GROUP BY propertyid
> )maxresults
> WHERE pr.propertyid = maxresults.propertyid
> AND pr.valuationdate = maxresults.maxdate
>
Yes, or you can use the subselect in the where clause itself.
The question is, what RDBMS is the OP using. If it is <MySQL 4.1
subselects are not supported for this case I would use something like this:

SELECT p1.propertyid, p1.valuationdate, p1.valuation FROM
properties p1 LEFT JOIN
properties p2 ON (p1.propertyid=p2.propertyid AND
p2.valuationdate>p1.valuationdate)
WHERE p2.valuationdate IS NULL

This can return more than one result for any id if there are more than
one entries with max(valuationdate) and the same id, So probably you
have to do a group by in this case.

Regards
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (MingW32)

iD8DBQFELo4uyeCLzp/JKjARAhuvAJ44IkBFCRwyWhjpMX5J2tP/U1UKRACgn2/C
b8SJEOt0c7Scd7ShkJcAXZE=
=ro6H
-----END PGP SIGNATURE-----

[Back to original 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

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