tricky query using NULLS
Posted in 1999
I've got a table called articleclass which contains meta data for one of
my central tables.
i've got a query which looks like this:
select articles.sportsym,articles.articletype_id,author.templateid
from articles,articleclass sport,articleclass atypeid,articleclassauthor
where
sport.templateid=atypeid.templateid and
atypeid.templateid=author.templateid and
(articles.author = author.author or atypeid.author is null) and
(articles.sportsym = sport.sportsym or sport.sportsym is null) and
(articles.articletype_id = atypeid.number or atypeid.number is null)
What I'm trying to get to is a mechanism wihch will return the template
based on the meta-data. I am trying to table-ize these rules so that I
can adminster them better than the 10000 lines of perl code does now.
As you can see, the 'or XXXXX is null' clause is rather tricky.
Am I making a bad move here? Can someone suggest a better approach?
The query almost works - its that almost part that bugs me.
BX 1 t.SportsBahr
CB 3 99t.articles
CB 3 99t.articles
CB 3 99t.articles
CB 3 99t.articles
notice that it correclty returns the template for the sportsbahr, but
the 99t.articles I think is a cartesian product due to the NULLs in the
sportsym column in the articleclass table. Yet I'd like to keep these to
represent the 'ALL SPORTS' condition.
I realize that this email is long and drawn out, but anyone has an idea
of a direction here, it'd be great.
Thanks for your time.
David Buttrick
The Sporting News