[prog] Sql query

Tiera tiera at bredband.net
Tue Jul 12 18:02:53 EST 2005


Hi!

I'm having some trouble coming up with a sql query that will work for the
following problem:

I have one table called product and one table called period.

product
-------
id
name
descr

period
------
id
productid
status
startdate
enddate

A period is connected one product, but a product can have one or more
periods connected to it. A period always has a startdate, but doesn't need
to have a enddate. If there is multiple periods for a product only one of
them can be without a enddate (the last one), but it could also be that
all the periods connected to a product has enddates.

My problem is that I would like to get all the products and the status
from the last period for every product. I think I could solve this with a
subquery, but I'm using a mysql-server, version 3.23, so it doesn't have
subqueries yet.

Does anyone know how/if this can be solved?

/Tiera



More information about the Programming mailing list