[prog] Sql query

Tiera tiera at bredband.net
Wed Jul 13 17:02:03 EST 2005


> May seem easy now but it'll be a big headache down the line.  Any
> redundant data means extra ongoing maintenance.  It would be better to get
> familiar with all the complex queries you can do such as:
>
> select * from product, period where
> product.id = period.productid
> and
> (period.enddate is null or period.status = 'Special')
>
> Which will allow both in one query...
>
> Conor

Hi again

Yes, I know... but I can't come up with anything else that works at the
moment. The problem with you query above is that the only status I'm
interested in is the status for the last period for every product. So if I
have a product that has two periods, the first one with status 'Special'
and the last one with status 'Ordinary' and I use your query to pick out
all products with status 'Special' I would get this product, but that's
not correct since this product now has status 'Ordinary'.
The problem would be much easier to solve if there always was one period
with no enddate...but unfortunately that's not the case. Or another column
that would tell if it was the last period or not...should have thought of
that earlier perhaps...

/Tiera



More information about the Programming mailing list