Nothing prevents you from adding a "Type" column to the second table to distinguish the two, if you need to. That way you may make the distinction if you want or treat them the same if you don't. Let's see the simplest query "find the description for this name, I don't know whether its a base name or an alias".
First design:
SELECT fact
FROM Facts
WHERE name = ?
and Type = 1
UNION
SELECT BaseFacts.fact
FROM Facts as BaseFacts
JOIN Facts as AliasFacts ON BaseFacts.fact_id = Convert(int,AliasFac
+ts.data)
WHERE AliasFacts.name = ?
and AliasFacts.Type = 2
and BaseFacts.Type = 1
-- and this all works only if you do not ever have an alias to an alia
+s!
Second design:
SELECT fact
FROM Facts
WHERE name = ?
UNION
SELECT fact
FROM Facts
JOIN Aliases ON Aliases.fact_id = Facts.fact_id
WHERE Aliases.name = ?
Third design:
SELECT fact
FROM Facts
JOIN Names ON Names.Fact_id = Facts.fact_id
WHERE Names.Name = ?
Which one do you like best? ;-)
Jenda
We'd like to help you learn to help yourself
Look around you, all you see are sympathetic eyes
Stroll around the grounds until you feel at home
-- P. Simon in Mrs. Robinson |
|