[prog] Sql query

Tiera tiera at bredband.net
Tue Jul 12 21:25:28 EST 2005


> Here's a solution that's a bit of a hack, but at least it doesn't
> require issuing queries in a loop.
>
> SELECT * FROM product, period WHERE product.id=period.productid ORDER BY
> product.id, period.startdate DESC;
>
> Then loop through the results and, when you encounter a new product.id,
> you know that you have the last period for that product.
>

I forgot to mention that I also need to be able pick out the products that
have a special status at the moment. I think I'll just put a status field
in the product table also and keep that up to date with the changes in the
period table. Seems like the easiest solution at the moment.

/Tiera



More information about the Programming mailing list