Subject | Finding best match |
---|---|
Author | ainpoissee |
Post date | 2006-10-11T17:42:05Z |
Hi,
I have table like
CREATE TABLE TAB_T (
UID INTEGER PRIMARY KEY,
Tsoon INTEGER NOT NULL,
FOsakond INTEGER,
FAllyksus INTEGER,
FAmet INTEGER
);
and I want to get UID for a given Tsoon value which best matches with
remaining fields. Ie given Tsoon = 10, FAllyksus = 1, FOsakond = 2,
FAmet = 3, if there is a row with these values then I want it's UID.
In case there isn't exact match, next best would be one where FOsakond
IS NULL but other columns do match.
If there isn't such one, then I want one where FAllyksus IS NULL but
FOsakond and FAmet do match. And so on... is there a way to make such
a query or do I have to try one by one till I find combination which
exists?
Priority of the fields is FAmet, FAllyksus, FOsakond, ie it is better
to have matching FAmet (with FAllyksus and FOsakond NULL) than
matching FAllyksus (with FAmet and FOsakond NULL).
TIA
ain
I have table like
CREATE TABLE TAB_T (
UID INTEGER PRIMARY KEY,
Tsoon INTEGER NOT NULL,
FOsakond INTEGER,
FAllyksus INTEGER,
FAmet INTEGER
);
and I want to get UID for a given Tsoon value which best matches with
remaining fields. Ie given Tsoon = 10, FAllyksus = 1, FOsakond = 2,
FAmet = 3, if there is a row with these values then I want it's UID.
In case there isn't exact match, next best would be one where FOsakond
IS NULL but other columns do match.
If there isn't such one, then I want one where FAllyksus IS NULL but
FOsakond and FAmet do match. And so on... is there a way to make such
a query or do I have to try one by one till I find combination which
exists?
Priority of the fields is FAmet, FAllyksus, FOsakond, ie it is better
to have matching FAmet (with FAllyksus and FOsakond NULL) than
matching FAllyksus (with FAmet and FOsakond NULL).
TIA
ain